Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
WillianAgostini opened this issue Dec 4, 2023 · 2 comments · Fixed by #14738
Closed

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

WillianAgostini opened this issue Dec 4, 2023 · 2 comments · Fixed by #14738

Comments

@WillianAgostini
Copy link
Contributor

🚀 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.

@WillianAgostini WillianAgostini changed the title [Feature]: [Feature]: add a waitBeforeRetry option to jest.retryTimes Dec 4, 2023
WillianAgostini added a commit to WillianAgostini/jest that referenced this issue Dec 4, 2023
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2024
@SimenB
Copy link
Member

SimenB commented Feb 20, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants