Reputation: 13459
When I added the setTimeout I got this error for:
// Suite
describe("sidebar", function() {
setTimeout(function(){
document.querySelector('.fa-bars').click();
expect(document.getElementById('sidebar')!=null).toEqual(true);
}, 2000);
});
But I don't understand how calling it in a setTimeout can even trigger this error?
Upvotes: 2
Views: 2155
Reputation: 66650
You need to call done callback:
describe("sidebar", function() {
it('should work with setTimeout', function(done) {
setTimeout(function(){
document.querySelector('.fa-bars').click();
expect(document.getElementById('sidebar')!=null).toEqual(true);
done();
}, 2000);
});
});
Upvotes: 1
Reputation: 877
you're using a synchronous test to test asynchronous code. Try
// Suite
describe("sidebar", function() {
runs( function(){ // encapsulates async code
setTimeout(function(){
document.querySelector('.fa-bars').click();
expect(document.getElementById('sidebar')!=null).toEqual(true);
}, 2000);
});
});
For more information, check out https://github.com/pivotal/jasmine/wiki/Asynchronous-specs
Upvotes: 2