I have a branch in a function that isn't currently being tested. It's an error handler coming from a request
operation (using the node module of the same name). Here is the particular line:
request(url, function (error, response, body) {
if (error) return cb(error);
Here is the test:
describe("handles errors", function() {
it("from the request", function (done) {
var api = nock('http://football-api.com')
.get('/api/?Action=today&APIKey=' + secrets.APIKey + '&comp_id=1204')
.reply(500);
fixture.getFixture(FixtureMock, function (err, fixture) {
expect(err).to.exist
done();
});
});
Spec fails:
Uncaught AssertionError: expected null to exist
So either sending a 500
status code as a response with no body does not cause an error
in the request callback, or I'm testing the wrong thing.
Use replyWithError
from doc:
nock('http://www.google.com')
.get('/cat-poems')
.replyWithError('something awful happened');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With