Skip to content

Commit

Permalink
docs(README): Update Axios example (#2464)
Browse files Browse the repository at this point in the history
* fix(README): Update axios example

This was added with #1711 but [has changed with axios v1](axios/axios#5277)
  • Loading branch information
depoulo committed Apr 26, 2023
1 parent 3a7c7c3 commit 3feef40
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -1539,8 +1539,10 @@ 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/axios/axios/pull/5277
// https://github.com/nock/nock/issues/699#issuecomment-272708264
// https://github.com/axios/axios/issues/305

axios.defaults.adapter = 'http'

test('can fetch test response', async t => {
Expand All @@ -1559,6 +1561,18 @@ 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:

```js
const config = {
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

0 comments on commit 3feef40

Please sign in to comment.