jasmine-jquery
jasmine-jquery copied to clipboard
toHandle and toHandleWith functions not behaving as expected.
I'm not sure if I am using the "toHandle" and "toHandleWith" functions incorrectly or if this is a bug, but here's what I am getting:
The "toHandle" function:
var testSubject = $( '#test-subject' );
testSubject.on( 'click', function () {
this.classList.add( 'clicked' );
} );
expect( testSubject ).toHandle( 'click' );
Returns (failed test):
Expected({
0: HTMLNode,
length: 1,
context: HTMLNode,
selector: '#test-subject'
}) to handle 'click'. at Object. < anonymous > (/tmp/f77c1f3da728079fcab542aba1420d746dc199bc.browserify: 22929: 31 < -tests / app.js: 511: 0)
The "toHandleWith" Function:
var testSubject = $( '#test-subject' );
var callback = function () {
this.classList.add( 'clicked' );
}
testSubject.on( 'click', callback );
expect( testSubject ).toHandleWith( 'click', callback );
Returns (error):
TypeError: Cannot read property 'click' of undefined at jasmine.addMatchers.toHandleWith.compare(/home/ (user) /Desktop/Projects / node_modules / karma - jasmine - jquery / lib / jasmine - jquery.js: 596: 60) at Object. < anonymous > (/tmp/f77c1f3da728079fcab542aba1420d746dc199bc.browserify: 22929: 31 < -tests / app.js: 511: 0)
I know the event is in fact being set because the following works:
var testSubject = $( '#test-subject' );
testSubject.on( 'click' , function () {
this.classList.add('clicked');
} );
testSubject.trigger( 'click' );
expect( testSubject.hasClass( 'clicked' ) ).toBeTruthy();
I'm using jasmine-jquery (v2.0.7). Thank you for your time.
EDIT: I originally installed jasmine-jquery via NPM through the karma-jasmine-jquery package, as part of a workflow involving Karma, Browserify, and Gulp. I'm inclined to think that it's an interference with one of those tools (most likely Browserify). To know for sure, I decided to isolate the jasmine-jquery library ( http://jsfiddle.net/marcbraulio/nqh7djsa/2/ ) and it appears that the tests pass without a problem.
EDIT: Just ran an installation without using Gulp and Browserify, so it appears that the problem is with karma-jasmine/karma-jasmine-jquery. I went ahead and posted this issue with the isolated Karma installation on the karma-jasmine-jquery github ( https://github.com/bessdsv/karma-jasmine-jquery/issues/7 ).
This issue can technically be considered closed, however if anyone can shed some light as to what might be causing this interference, I would highly appreciate it.