Why does this test not pass?
beforeEach(function(){
loadFixtures('addvehicle.html');
});
it ("should trigger change event on #selectLanguage", function(){
spyOnEvent('#selectLanguage', 'change');
$('#selectLanguage').trigger('change');
expect('change').toHaveBeenTriggeredOn('#selectLanguage');
});
My fixture file looks like this:
<div id="selectTypeWrapper"></div>
<select id="selectLanguage"></select>
I get this error:
Error: Expected event [object Object] to have been triggered on #selectLanguage
Do I have to set a change listener before? (how would this work?)
I don't know why your code does not work, but maybe you could try this:
var changeSpy;
beforeEach(function(){
loadFixtures('addvehicle.html');
changeSpy = jasmine.createSpy('handleChange() spy');
$('#selectLanguage').change(changeSpy);
});
it ("should trigger change event on #selectLanguage", function(){
$('#selectLanguage').change();
expect(changeSpy).toBeDefined();
expect(changeSpy).toHaveBeenCalled();
});
It will test the event indirectly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.