Jest

Asynchronous or time-based events (timers)

describe('do some crazy stuff with timers.', () => {
  beforeEach(() => {
    // declare the intent of using timers
    jest.useFakeTimers()
  })

 it('should .', () => {
    // mock if needed
    const callback = jest.fn()

    // mount component

    // follow by expect before timers

    // execute timers
    jest.runAllTimers()

    // expect something after timers have been executed
    expect(callback).toHaveBeenCalledTimes(1)
  })

Verify that function was called with multiple arguments

.toHaveBeenCalledWith(arg1, arg2, ...)

Also available under the alias: .toBeCalledWith()

Verify that the same function was called multiple times with different arguments

Last updated

Was this helpful?