Skip to content

jest.fn().waitUntilCalledNTimes() Feature #7432

@benjaminkay93

Description

@benjaminkay93

🚀 Feature Proposal

Add some kind to feature to jest to wait until a mock function has been called n times.

Motivation

We have an API that recursively sends periodic notifications to another service, we need to check that this works, we currently have a setTimeout wrapped in a promise to make the test wait for a period thats deffinetly longer than needed.

Example

test('some test', async () => {
  const someMock = jest.fn()

  await someMock.waitUntilCalledNTimes(n) // on the nth call, continue.

  expect(someOtherMock).hasBeenCalled()
})

Pitch

Why does this feature belong in the Jest core platform?

It would be an addition to the core jest mocking ability, allowing for dynamic tests ensuring that a function has to of been called n times before moving on to check for its asssertions

Im happy to give this ago myself, if its something thats wanted

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions