Bug Tracker

Changeset 4436

Show
Ignore:
Timestamp:
01/14/08 09:33:08 (1 year ago)
Author:
joern.zaefferer
Message:

fix for #2114; refactored tests for bind() to highlight failing select-change-test

Location:
trunk/jquery
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r4434 r4436  
    3939 
    4040        // Handle $(DOMElement) 
    41         if ( selector.nodeType ) { 
     41        if ( selector.nodeType && !selector.length ) { 
    4242            this[0] = selector; 
    4343            this.length = 1; 
     
    9494            // HANDLE: $(arraylike) 
    9595            // Watch for when an array-like object, contains DOM nodes, is passed in as the selector 
    96             (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) || 
     96            (selector.jquery || selector.length && selector != window && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) || 
    9797 
    9898            // HANDLE: $(*) 
  • trunk/jquery/test/unit/event.js

    r4251 r4436  
    11module("event"); 
    22 
    3 test("bind()", function() { 
    4     expect(19); 
    5  
     3test("bind(), with data", function() { 
     4    expect(3); 
    65    var handler = function(event) { 
    76        ok( event.data, "bind() with data, check passed data exists" ); 
     
    1110 
    1211    ok( !jQuery.data($("#firstp")[0], "events"), "Event handler unbound when using data." ); 
    13      
    14     reset(); 
     12}); 
     13 
     14test("bind(), with data, trigger with data", function() { 
     15    expect(4); 
    1516    var handler = function(event, data) { 
    1617        ok( event.data, "check passed data exists" ); 
     
    2021    }; 
    2122    $("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler); 
    22      
    23     reset(); 
    24     var clickCounter = mouseoverCounter = 0; 
     23}); 
     24 
     25test("bind(), multiple events at once", function() { 
     26    expect(2); 
     27    var clickCounter = 0, 
     28        mouseoverCounter = 0; 
    2529    var handler = function(event) { 
    2630        if (event.type == "click") 
     
    3236    ok( clickCounter == 1, "bind() with multiple events at once" ); 
    3337    ok( mouseoverCounter == 1, "bind() with multiple events at once" ); 
    34      
    35      
    36     reset(); 
     38}); 
     39 
     40test("bind(), no data", function() { 
     41    expect(1); 
    3742    var handler = function(event) { 
    3843        ok ( !event.data, "Check that no data is added to the event object" ); 
    3944    }; 
    4045    $("#firstp").bind("click", handler).trigger("click"); 
    41      
    42      
     46}); 
     47 
     48test("bind(), iframes", function() { 
    4349    // events don't work with iframes, see #939 - this test fails in IE because of contentDocument 
    4450    // var doc = document.getElementById("iframe").contentDocument; 
     
    5157    //  ok( true, "Binding to element inside iframe" ); 
    5258    // }).click(); 
    53      
     59}); 
     60 
     61test("bind(), trigger change on select", function() { 
     62    expect(3); 
    5463    var counter = 0; 
    5564    function selectOnChange(event) { 
     
    5968        $(this).bind('change', i, selectOnChange); 
    6069    }).trigger('change'); 
    61  
    62     reset(); 
     70}); 
     71 
     72test("bind(), namespaced events, cloned events", function() { 
     73    expect(6); 
    6374 
    6475    $("#firstp").bind("click",function(e){ 
     
    90101    $("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p"); 
    91102    ok( $("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); 
    92     reset(); 
    93103}); 
    94104