src/custom-hooks/useFetch.js change URL methods of passing change with props.
Files to add
setupTests.ts add teardown
mocks/server.ts add server
mocks/handler.ts add handler
hooks/useAxios.ts feat: useFetch hook.
__tests__/useAxios.ts test for useFetch hook.
UseAxios hook
The useAxios hook is a custom React hook for making HTTP requests with the axios library. It returns an object with three properties: data, loading, and error. The data property contains the response data, the loading property is a boolean that indicates whether the request is in progress, and the error property contains any error that occurred during the request.
The hook accepts a URL, an HTTP method (defaults to GET), and a configuration object that can be used to pass additional options to axios
UseAxios hook test
The tests for the useAxios hook use the msw library to mock HTTP requests and verify that the hook returns the expected values for different scenarios, such as successful requests and failed requests.
Issue
Files to change
jest.config.js
for test setuppackage.json
src/custom-hooks/useFetch.js
change URL methods of passing change with props.Files to add
setupTests.ts
add teardownmocks/server.ts
add servermocks/handler.ts
add handlerhooks/useAxios.ts
feat: useFetch hook.__tests__/useAxios.ts
test for useFetch hook.UseAxios hook
useAxios
hook is a custom React hook for making HTTP requests with theaxios
library. It returns an object with three properties:data
,loading
, anderror
. Thedata
property contains the response data, theloading
property is a boolean that indicates whether the request is in progress, and theerror
property contains any error that occurred during the request.GET
), and a configuration object that can be used to pass additional options toaxios
UseAxios hook test
useAxios
hook use themsw
library to mock HTTP requests and verify that the hook returns the expected values for different scenarios, such as successful requests and failed requests.get
,patch
andreject
request during testing.