Put in order · JavaScript and TypeScript course · Module 11: Testing with Jest

Steps for Asynchronous Testing

Arrange the steps for testing asynchronous code with fake timers:

Items to put in order

  • Verify the result: expect(...).toHaveBeenCalled()
  • Run the tested function with a timer
  • Restore timers: jest.useRealTimers()
  • Enable fake timers: jest.useFakeTimers()
  • Advance time: jest.advanceTimersByTime(ms)

You can check the correct answer by solving this task in the CodeWorlds game.