I am trying to test the removeEventListener with jasmine. I have
describe('test', function(){
'use strict';
beforeEach(function() {
affix('#test');
method = {
test: function() {
console.log('hi!');
}
}
spyOn(method, 'test');
$selectedElement = $('#test');
selectedElement = $selectedElement[0];
});
it('should remove event listener', function(){
selectedElement.addEventListener('click', method.test);
selectedElement.removeEventListener('click', method.test);
$selectedElement.click();
expect(methods.showLove).not.toHaveBeenCalled();
});
});
But this fails. Now I suppose this is because I have anonymous function here. Is there a way to remedy this without using non anonymous function?
If I put
function clickMe() {
return 'bla';
}
and use that instead of method.test in the event listeners the test is successful. How to use the functions defined in the methods?
Aucun commentaire:
Enregistrer un commentaire