Skip to content Skip to sidebar Skip to footer

How To Deal With Thrown Errors In Async Code With Jasmine?

The following test causes Jasmine (2.3.4, run in browser via Karma) to crash and not run any subsequent tests it('should report as failure and continue testing', function (done) {

Solution 1:

Mocking the clock will give you the expected result. Mocking the clock in general is a best practice for testing timeouts.

describe('foo', function () {
    beforeEach(function () {
        timerCallback = jasmine.createSpy("timerCallback");
        jasmine.clock().install();
    });
    afterEach(function () {
        jasmine.clock().uninstall();
    });
    it('should report as failure and continue testing', function (done) {
        setTimeout(function () {
            throw new SyntaxError('some error');
            done();
        }, 1000);
        jasmine.clock().tick(1001);
    });
});

Post a Comment for "How To Deal With Thrown Errors In Async Code With Jasmine?"