Created
January 30, 2019 08:20
-
-
Save ivankisyov/1a39de00e275b0d3d2be7a401436b1e3 to your computer and use it in GitHub Desktop.
Faking a server using Nock
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
// npm install those first | |
const nock = require("nock"); | |
const axios = require("axios"); | |
nock("http://www.example.com") | |
.post("/items") | |
.reply(201, "user created"); | |
axios | |
.post("http://www.example.com/items", { | |
name: "smith", | |
id: 11 | |
}) | |
.then(result => { | |
console.log("result>>>", result); | |
}) | |
.catch(err => { | |
console.log("err>>>", err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment