mirror of
https://github.com/simoneb/axios-hooks.git
synced 2025-12-08 21:25:56 +00:00
fix: lingering error (#908)
This commit is contained in:
parent
b48caf1270
commit
695cc84d1d
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@ -0,0 +1,3 @@
|
||||
cjs
|
||||
coverage
|
||||
es
|
||||
@ -1,6 +1,5 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@babel/eslint-parser",
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:import/recommended",
|
||||
@ -8,7 +7,7 @@
|
||||
"plugin:react-hooks/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
"ecmaVersion": "latest"
|
||||
},
|
||||
"env": {
|
||||
"browser": true,
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
"build": "run-p build:*",
|
||||
"clean": "rimraf cjs es",
|
||||
"format": "prettier --write \"{src,test}/**/*.{js?(x),md,ts?(x)}\"",
|
||||
"lint": "eslint src test",
|
||||
"lint": "eslint . --ext .js,.jsx",
|
||||
"prepare": "npm run clean && npm run build && husky install",
|
||||
"release": "standard-version",
|
||||
"pretest": "cp ./test/index.test.jsx ./test/index.test.tsx && cp ./test/index.test.ssr.jsx ./test/index.test.ssr.tsx",
|
||||
@ -44,7 +44,6 @@
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.17.10",
|
||||
"@babel/core": "7.18.2",
|
||||
"@babel/eslint-parser": "7.18.2",
|
||||
"@babel/plugin-transform-runtime": "7.18.2",
|
||||
"@babel/preset-env": "7.18.2",
|
||||
"@babel/preset-react": "7.17.12",
|
||||
|
||||
@ -151,7 +151,9 @@ export function makeUseAxios(configureOptions) {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
...(action.error ? {} : { data: action.payload.data }),
|
||||
// set data and error
|
||||
...(action.error ? {} : { data: action.payload.data, error: null }),
|
||||
// set raw response or error
|
||||
[action.error ? 'error' : 'response']: action.payload
|
||||
}
|
||||
}
|
||||
|
||||
@ -1023,6 +1023,32 @@ function standardTests(
|
||||
|
||||
expect(axios).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should reset error when one successful request follows a failing request', async () => {
|
||||
axios.mockResolvedValueOnce({ data: 'working 1' })
|
||||
|
||||
const { result, waitForNextUpdate, rerender } = setup('working')
|
||||
|
||||
await waitForNextUpdate()
|
||||
|
||||
const error = new Error('boom')
|
||||
|
||||
axios.mockRejectedValueOnce(error)
|
||||
|
||||
rerender({ config: 'boom', options: {} })
|
||||
|
||||
await waitForNextUpdate()
|
||||
|
||||
expect(result.current[0].error).toBe(error)
|
||||
|
||||
axios.mockResolvedValueOnce({ data: 'working 2' })
|
||||
|
||||
rerender({ config: 'working', options: {} })
|
||||
|
||||
expect(result.current[0].error).toBe(null)
|
||||
// because it's coming from cache
|
||||
expect(result.current[0].data).toBe('working 1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('configure', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user