Test Timing-Based Code With Jest Fake Timers
const doSomethingAfter200ms = doSomething => {
setTimeout(() => {
doSomething();
}, 200);
};describe("doSomethingAfter200ms", () => {
test("does something after 200ms (fail)", () => {
const doSomething = jest.fn();
doSomethingAfter200ms(doSomething);
expect(doSomething).toHaveBeenCalled();
});
});Last updated