Created
September 26, 2018 01:31
-
-
Save JaosnHsieh/4549e17ad12d8069bb7d582940cb045a to your computer and use it in GitHub Desktop.
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
const nock = require("nock"); | |
const axios = require("axios"); | |
var scope = nock("http://www.example.com") | |
.get("/resource") | |
.reply(200, "domain matched"); | |
axios.get("http://www.example.com/resource").then(body => { | |
console.log("1.--------------mocking response"); | |
console.log("body.status", body.status); | |
scope.done(); | |
axios | |
.get("http://www.example.com/resource") | |
.then(body => { | |
console.log("2.------------real response"); | |
console.log("body.status", body.status); | |
}) | |
.catch(err => { | |
console.log("2.------------real response"); | |
console.log("err", err.status); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment