Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

refetch does not respect the mock argument for lazy hooks #383

Open
abhinavrastogi opened this issue Jan 7, 2022 · 0 comments
Open

refetch does not respect the mock argument for lazy hooks #383

abhinavrastogi opened this issue Jan 7, 2022 · 0 comments

Comments

@abhinavrastogi
Copy link
Contributor

Describe the bug
When useGet hook is intialised with options lazy: true and mock: { ... }, calling refetch returns the mock response, but still makes the network call. This works in the browser, but causes issues in test environments where making API calls is not allowed.

Eg. Jest running in JSDom env fails with the error ReferenceError: Request is not defined and the following stack trace:

ReferenceError: Request is not defined
            at _temp2 (/Users/abhinavrastogi/project/node_modules/restful-react/src/useGet.tsx:172:23)
            at requestOptions (/Users/abhinavrastogi/project/node_modules/restful-react/src/useGet.tsx:167:19)
            at fetchData (/Users/abhinavrastogi/project/node_modules/restful-react/src/useGet.tsx:163:84)
            at /Users/abhinavrastogi/project/node_modules/restful-react/src/useGet.tsx:285:7

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/frosty-turing-pppqs?file=/src/App.js
  2. Open browser dev-tools
  3. Click on 'Refetch' button
  4. See that network panel shows the network call being made, but the response displayed is from the mock object

Expected behavior
Calling refetch when mock is present, should not trigger the actual network call.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: macOS
  • Browser Firefox
  • Version 95

Additional context
N/A

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant