Skip to content

Instantly share code, notes, and snippets.

@JaosnHsieh
Created September 26, 2018 01:31
Show Gist options
  • Save JaosnHsieh/4549e17ad12d8069bb7d582940cb045a to your computer and use it in GitHub Desktop.
Save JaosnHsieh/4549e17ad12d8069bb7d582940cb045a to your computer and use it in GitHub Desktop.
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