Skip to content

Instantly share code, notes, and snippets.

@enzzoperez
Created April 18, 2022 17:08
Show Gist options
  • Save enzzoperez/195a771ae16eee4c1a8768e9399e699e to your computer and use it in GitHub Desktop.
Save enzzoperez/195a771ae16eee4c1a8768e9399e699e to your computer and use it in GitHub Desktop.
it('testing error in request', async () => {
const mock = new MockAdapter(axios);
mock.onGet().reply(404, {data: []}); //or mock.onGet().networkError();
const {result, waitForNextUpdate} = renderHook(
({url}) => useRemoteData({url}),
{
initialProps: {
url: '',
},
},
);
await waitForNextUpdate();
expect(result.current.error).toBeTruthy();
expect(result.current.response).toBeFalsy();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment