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 all 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
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
Copy link
Contributor Author

@depoulo depoulo Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this no longer works, which is the whole point of my PR, same for the link right below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @depoulo, that was me messing up the rebase. I'll remove those two lines in another PR I have open for approval atm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries, and thanks for merging!

// 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 = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

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