Repository navigation
ADD: axios example - #1711
Merged
Merged
ADD: axios example#1711
Conversation
paulmelnikow
reviewed
Sep 6, 2019
| await axios.get('/test'); | ||
| t.is(call.isDone(), true); | ||
| }); | ||
| ``` |
Member
There was a problem hiding this comment.
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!
Contributor
Author
There was a problem hiding this comment.
I like u idea. I modify my change or u modify my change?
Contributor
Author
There was a problem hiding this comment.
I like ur idea. I modify my change or u modify my change?
Collaborator
|
🎉 This PR is included in version 11.3.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
depoulo
added a commit
to depoulo/nock
that referenced
this pull request
Apr 17, 2023
This was added with nock#1711 but [has changed with axios v1](axios/axios#5277)
mastermatt
pushed a commit
that referenced
this pull request
Apr 26, 2023
* fix(README): Update axios example This was added with #1711 but [has changed with axios v1](axios/axios#5277)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Nock community,
I would like to add back the knowledge of
axiosin Readme. ThanksNockteam. It is a very powerful testing package.Reference
#699 (comment)
Best,
Alpha