I have been debugging this Jasmine spec:
it(`should return tactic`, (done) => {
source.updateTactic(1, {
startDate: new Date(),
endDate: new Date(),
name: 'First Tactic',
}).subscribe((response) => {
expect(response).toEqual(updatedTacticJsonResponse);
});
http.expectOne(`${BASE_URL}/v1/tactics/1`).flush(updatedTacticJsonResponse);
});
with error message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
It turns out that done() was missing after the api call. The reason is that done()
is to let Jasmine know when an asynchronous function is complete. Without that, Jasmine never knows that your call is complete and will timeout eventually.
A correct spec would be:
it(`should return tactic`, (done) => {
source.updateTactic(1, {
startDate: new Date(),
endDate: new Date(),
name: 'First Tactic',
}).subscribe((response) => {
expect(response).toEqual(updatedTacticJsonResponse);
});
done();
http.expectOne(`${BASE_URL}/v1/tactics/1`).flush(updatedTacticJsonResponse);
});
Checkout Jasmine Documentation on Async
This spec will not start until the done function is called in the call to beforeEach above. And this spec will not complete until its done is called.