bessdsv / karma-jasmine-jquery

Jasmine-jquery plugin for Jasmine in Karma
Other
18 stars 55 forks source link

toHandle and toHandleWith functions not behaving as expected. #7

Open m-a-r-c-e-l-i-n-o opened 9 years ago

m-a-r-c-e-l-i-n-o commented 9 years ago

Hello,

I originally posted this bug report on the jasmine-jquery github ( https://github.com/velesin/jasmine-jquery/issues/251 ), but it appears that the issue is Karma related. The bug is as follows:

The "toHandle" function:

var testSubject = $( '#test-subject' );

testSubject.on( 'click', function () {

    // my callback
} );

expect( testSubject ).toHandle( 'click' );

Returns (failed test):

Expected ({ 
    0: HTMLNode, 
    length: 1, 
    context: HTMLNode, 
    selector: '#test-subject' 
}) to handle 'click'. at Object.<anonymous> (/home/marcbraulio/Projects/test/test/hello-world.js:27:31)

The "toHandleWith" Function:

var testSubject = $( '#test-subject' );

var callback = function () {

    // my callback
}

testSubject.on( 'click', callback );

expect( testSubject ).toHandleWith( 'click', callback );

Returns (error):

TypeError: Cannot read property 'click' of undefined at compare (/home/marcbraulio/Projects/test/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:596:60) at Object.<anonymous> (/home/marcbraulio/Projects/test/test/hello-world.js:41:31)

This is happening in an isolated installation of the following packages (running on Ubuntu 15.04): jasmine-core@2.3.2 karma@0.12.31 karma-jasmine@0.3.5 karma-jasmine-jquery@0.1.1 jquery@2.1.4

I narrowed it down to Karma because with an isolated installation using just jasmine with jasmine-jquery, both of those tests pass. This can be seen here: http://jsfiddle.net/marcbraulio/nqh7djsa/2/

Thank you for your time.

matteoantoci commented 9 years ago

+1 for this issue

scamden commented 8 years ago

+1 for me the issue seems related to the change from jquery 1.x to 2.x in terms of how data is handled. in 2.x the data is right on the element, since jasmine-jquery uses the data function of version 2 to get the events array it cannot get that data for element bound with jquery version 1.x which stores the data in a global cache.

scamden commented 8 years ago

update: looks like if you use the karma-jquery framework instead of manually including the 1.x version of jquery and place it after jasmine-jquery in the list of frameworks the bug is solved