Created
May 1, 2016 12:07
-
-
Save tobythetester/c375750ff921220e9d99f93f49e712b6 to your computer and use it in GitHub Desktop.
Mocked response from file
This file contains 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
var nock = require('nock'); | |
var request = require('supertest')("http://api.postcodes.io"); | |
var expect = require('chai').expect; | |
//used to read the JSON file | |
var fs = require("fs"); | |
describe("Testing API with a mocked backend", function () { | |
it("responds with json file response", function (done) { | |
//read the json file | |
var contents = fs.readFileSync('mockedresponse.json'); | |
//parse the contents and assign to a variable | |
var jsonContent = JSON.parse(contents); | |
nock("http://api.postcodes.io") | |
.get('/postcodes/') | |
.reply(200, jsonContent); | |
request | |
.get('/postcodes/') | |
.expect(200) | |
.end(function (err, res) { | |
expect(res.body.status).to.equal(200); | |
expect(res.body.result.postcode).to.equal("SW1A 1AA") | |
done(); | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment