karma-jasmine-jquery
karma-jasmine-jquery copied to clipboard
toHandle and toHandleWith functions not behaving as expected.
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): [email protected] [email protected] [email protected] [email protected] [email protected]
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.
+1 for this issue
+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.
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