Last active
May 1, 2016 12:28
-
-
Save tobythetester/45c45e19bdb4abf99e32ecd2bb5a421a to your computer and use it in GitHub Desktop.
Mocked Time Out
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; | |
describe("Testing API with a mocked backend", function () { | |
it("returns a successful mocked response", function (done) { | |
//override the mocha timeout in this test to 60 seconds | |
this.timeout(60000); | |
//setup mocked backend for a specific end point | |
nock("http://api.postcodes.io") | |
.get('/postcodes/') | |
//simulate a 10 second delay | |
.delayBody(10000) | |
.reply(200, { | |
"status": 200, | |
"message": "This simulates a 10 second delay" | |
}); | |
//perform the request to the api which will now be intercepted by nock | |
request | |
.get('/postcodes/') | |
.end(function (err, res) { | |
expect(res.body.status).to.equal(200); | |
expect(res.body.message).to.equal("This simulates a 10 second delay"); | |
done(); | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment