Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 673 Bytes

use-mock-clock-in-jasmine.md

File metadata and controls

22 lines (18 loc) · 673 Bytes

Use a mock clock in Jasmine (2016-02-15)

Jasmine (1.3, in this case) allows you to mock the clock:

beforeEach(() => {
    jasmine.Clock.useMock();
});

it('should do awesome stuff', () => {
    var awesome = false;

    setTimeout(() => {
                   awesome = true;
               },
               60000);
    expect(awesome).toEqual(false);

    jasmine.Clock.tick(60000);
    expect(awesome).toEqual(true);
});

Of course, this test won't run for 60 seconds. For this reason, using mock clock should be preferred over setting timeouts with expectations.