February 2019
Beginner
694 pages
18h 4m
English
Jasmine uses a function named done to help us with these sorts of asynchronous tests. In any beforeEach, afterEach, or it function, we pass an argument named done (which is a function), and then invoke it at the end of our asynchronous code. Let's rewrite our previous test for executeSlowFunction, as follows:
describe("asynch tests with done", () => { let returnedValue!: string; beforeEach((done) => { returnedValue = "no_return_value"; let mockAsync = new MockAsyncClass(); console.log(`1. calling executeSlowFunction`); mockAsync.executeSlowFunction((value: string) => { console.log(`2. executeSlowFunction returned`); returnedValue = value; done(); }); }); it("should return success after 1 second", (done) => { console.log(`3. checking ...Read now
Unlock full access