Mocking console.log with jestdescribe("outer", () => { describe("inner", () => { let spy: jest.SpyInstance; beforeAll(() => { spy = jest.spyOn(global.console, "log").mockImplementation(); }); afterAll(() => { spy.mockRestore(); }); it("do...Jun 6, 2021 · 1 min read
Jun 6, 2021Jun 6, 2021 · 1 min readUsing jest toThrow with async / awaitInstead of it("doesn't work", async () => { const fn = async () => { throw new Error(); }; expect(await fn()).toThrow(); }); Use it("does work", async () => { const fn = async () => { throw new Error(); }; await expect(fn()).r...1 min read