Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(README): Update axios example #2464

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,8 @@ import test from 'ava' // You can use any test framework.
// can't be intercepted by nock. So, configure axios to use the node adapter.
//
// References:
// https://github.com/nock/nock/issues/699#issuecomment-272708264
// https://github.com/axios/axios/issues/305
axios.defaults.adapter = require('axios/lib/adapters/http')
// https://github.com/axios/axios/pull/5277
axios.defaults.adapter = 'http'

test('can fetch test response', async t => {
// Set up the mock request.
Expand All @@ -1559,6 +1558,16 @@ test('can fetch test response', async t => {
})
```

For Nock + Axios + Jest to work, you'll have to also adapt your jest.config.js, like so:

```
depoulo marked this conversation as resolved.
Show resolved Hide resolved
moduleNameMapper: {
// Force CommonJS build for http adapter to be available.
// via https://github.com/axios/axios/issues/5101#issuecomment-1276572468
'^axios$': require.resolve('axios'),
```


[axios]: https://github.com/axios/axios

### Memory issues with Jest
Expand Down