Created
September 30, 2017 15:52
-
-
Save LearningNerd/7acfa738564d45ebd1fda4d960184ed7 to your computer and use it in GitHub Desktop.
Code by @gr2m -- 5 min example he showed me of how @node-nock can mock an API for testing
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 assert = require('assert') | |
const nock = require('nock') | |
const axios = require('axios') | |
// nock('https://api.github.com') | |
// .get('/') | |
// .reply(200, { | |
// current_user_url: 'https://api.github.com/user' | |
// }) | |
nock.recorder.rec() | |
myLib() | |
.then(result => { | |
assert.equal(result.current_user_url, 'https://api.github.com/user') | |
console.log('ok') | |
}, assert.ifError) | |
function myLib () { | |
return axios.get('https://api.github.com') | |
.then(result => result.data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment