Prevent console errors during tests #5148
-
When testing API error cases, an error must be thrown from the query function in order to trigger the error state. This may be because of a server error or some other scenario that is expected to occur from time to time and warrants testing. However this results in console errors. Previously we could override this behaviour by giving a custom logging function for console errors, but this has been deprecated and no alternative provided. In #622, it was said that errors won't be logged to the console any more except where the developer should do something about them, but that doesn't seem to be the case to me. See a minimal reproduction using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi 👋 You don't need to throw an error. You could also reject the promise. The In version 4, errors are no longer logged to the console in production. They are still logged in other environments. Please see https://tanstack.com/query/v4/docs/react/guides/migrating-to-react-query-4#logging-in-production Providing a noop error logging function removes the error 🙂 |
Beta Was this translation helpful? Give feedback.
Hi 👋
You don't need to throw an error. You could also reject the promise.
The
setLogger
function has been removed but you can still provide custom logging functions when instantiating the query client. Please see https://tanstack.com/query/v4/docs/react/guides/migrating-to-react-query-4#setlogger-is-removed.In version 4, errors are no longer logged to the console in production. They are still logged in other environments. Please see https://tanstack.com/query/v4/docs/react/guides/migrating-to-react-query-4#logging-in-production
Providing a noop error logging function removes the error 🙂