Skip to content

The default logger makes for a poor testing experience when testing network errors #2561

@VanTanev

Description

@VanTanev

Describe the bug
The default logger will log an error to console on failed network requests, eg:

https://github.com/tannerlinsley/react-query/blob/6bbb3710e5fae3bd8c425048be3a2b7f14c29100/src/core/mutation.ts#L196

While this makes sense for dev/prod use, when writing tests it produces unnecessary noise. Errors are logged to the console even for passing tests.

Expected behavior
Either the logger should switch to a null logger when process.env.NODE_ENV === 'test', or the testing docs should be amended to instruct developers to do something like:

import { setLogger } from 'react-query'

let noop = () => {}
beforeAll(() => {
  setLogger({
    log: noop,
    warn: noop,
    error: noop
  })
}) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions