-
-
Notifications
You must be signed in to change notification settings - Fork 745
ADD: axios example #1711
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
ADD: axios example #1711
Conversation
README.md
Outdated
await axios.get('/test'); | ||
t.is(call.isDone(), true); | ||
}); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thanks for opening this.
Could I suggest using this snippet (assuming it works)? It matches the naming and style of the rest of nock + the readme, doesn't set host which isn't strictly necessary, and adds some comments.
import axios from 'axios'
import nock from 'nock'
import test from 'ava' // You can use any test framework.
// If you are using jsdom, axios will default to using the XHR adapter which
// can't be intercepted by nock. So, configure axios to use the node adapter
// instead.
//
// 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')
test('can fetch test response', async t => {
// Set up the mock request.
const scope = nock('http://localhost')
.get('/test')
.reply(200, 'test response')
// Make the request. Note that the hostname must match exactly what is passed
// to `nock()`. Alternatively you can set `axios.defaults.host = 'http://localhost'`
// and run `axios.get('/test')`.
await axios.get('http://localhost/test')
// Assert that the expected request was made.
scope.done()
})
Also, there's a section "Common issues" in the readme. Would you mind moving this new section there?
I hadn't read those threads before – it's good to know about!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like u idea. I modify my change or u modify my change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like ur idea. I modify my change or u modify my change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated yours!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
🎉 This PR is included in version 11.3.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This was added with nock#1711 but [has changed with axios v1](axios/axios#5277)
* fix(README): Update axios example This was added with #1711 but [has changed with axios v1](axios/axios#5277)
Hi Nock community,
I would like to add back the knowledge of
axios
in Readme. ThanksNock
team. It is a very powerful testing package.Reference
#699 (comment)
Best,
Alpha