Skip to content

[Feature]: add a waitBeforeRetry option to jest.retryTimes #14737

@WillianAgostini

Description

@WillianAgostini

🚀 Feature Proposal

It would be nice to be able to tell Jest to wait some amount of time before retrying tests. I think for most use cases, just a static number of milliseconds would be sufficient.
Based on #13659

Motivation

I have a test for an API that relies on a third-party API to execute successfully. Using a mock is not feasible in this scenario, as the test requires fetching real-time data directly from the API. However, there are instances where timeout errors occur. To address this issue, I am considering the use of jest.retryTimes. The rationale behind this approach is to introduce a timeout between tests that may require a retry, thus mitigating timeout errors.

Example

describe('Updating item', () => {

  describe('subsequent queries', () => {
    jest.retryTimes(3, { waitBeforeRetry: 10e3 })
  
    test('getting item should show updates', async () => {
      const item = await getFromRemoteApi('example.com/users')
      expect(item.length).toEqual(2)
    })
  })
})

Pitch

Utilize a time interval between tests, as there are situations where the API is temporarily unavailable. The use of new attempts after the timeout period may lead to success in the CI process.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions