Replies: 1 comment 2 replies
-
I think it depends on the implementation of your fetcher. If it's resolved as it('should not assign the error object to the data when an error occured', async () => {
function Page() {
const { data, error } = useSWR(
'error-10',
() => new Promise((_, rej) => rej({ message: 'error!'}))
)
if (typeof data === "undefined" && error) return <div>{error.message}</div>
return <div>hello, {data}</div>
}
const { container } = render(<Page />)
expect(container.firstChild.textContent).toMatchInlineSnapshot(`"hello, "`)
// mount
await screen.findByText('error!')
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Given an error like this being sent from an express API:
res.status(500).send({ message: 'Message' })
Even while throwing in the fetcher, the response body (
{message: 'Message'}
) is still being set asdata
:const { data } = useSWR(endpoint) // data should be undefined or a cached value, not the error response body
Am I missing something? Do I have to just not send a response body at all?
Beta Was this translation helpful? Give feedback.
All reactions