Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  195] [ 5]  / answers: 1 / hits: 52888  / 9 Years ago, mon, march 23, 2015, 12:00:00

Having trouble with jasmine 2 and getting async specs wired up:



define(['foo'], function(foo) {
return describe('foo', function() {
beforeEach(function(done) {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
return setTimeout((function() {
console.log('inside timeout');
return done();
}), window.jasmine.DEFAULT_TIMEOUT_INTERVAL);
});
return it('passes', function() {
return expect({}).toBeDefined();
});
});
});


When I run via karma, I get back




Error: Timeout - Async callback was not invoked within timeout
specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.




and then the specs fail. I have attempted to override the default timeout but I can't get past the error


More From » jasmine

 Answers
9

You are using the same timeout interval as Jasmine is using to fail tests on timeout, i.e. your timeout is triggered to fire with Jasmine's default interval, which fails the test.



If you set your timeout to be less than jasmine default timeout the test passes.



describe('foo', function () {
beforeEach(function (done) {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
setTimeout(function () {
console.log('inside timeout');
done();
}, 500);
});
it('passes', function () {
expect({}).toBeDefined();
});
});


See fiddle here


[#67339] Friday, March 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katelinb

Total Points: 535
Total Questions: 104
Total Answers: 109

Location: Burkina Faso
Member since Sun, Jun 13, 2021
3 Years ago
;