Skip to content

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

@prabirshrestha

Description

@prabirshrestha

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

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