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

Add pattern to disable retry for react-query in test files #210

Open
prabirshrestha opened this issue Jun 26, 2024 · 0 comments
Open

Add pattern to disable retry for react-query in test files #210

prabirshrestha opened this issue Jun 26, 2024 · 0 comments

Comments

@prabirshrestha
Copy link

Suggest adding a pattern to disable retry in react-query client in tests. This was something we discovered while investigating slow unit tests. By default react-query retries 3 times exponentially, having this rule allows to disable the retry thus allowing tests to run faster.

version: 0.0.1
patterns:
  - name: react_query_client_disable_retry_in_test
    tags: ['react-query', 'testing']
    level: error
    description: |
      Disable retries in React Query client for testing.
    body: |
      `new QueryClient()` => `new QueryClient({ defaultOptions: { queries: { retry: false } } })`
    samples:
      - input: |
          new QueryClient()
        output: |
          new QueryClient({ defaultOptions: { queries: { retry: false } } })

There is probably a better way to do this, but the above pattern worked for us in our codebase.

For reference: Here is the doc. https://tanstack.com/query/v5/docs/framework/react/guides/testing#turn-off-retries

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

No branches or pull requests

1 participant