Skip to content

Commit

Permalink
Error handling tests
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Vaughan-Jones <[email protected]>
  • Loading branch information
chrisandrews7 and bvjones committed Nov 27, 2018
1 parent 5978c8a commit aba21b3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
node_modules
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";

const equal = require('deep-equal');

module.exports = (chai) => {
Expand Down Expand Up @@ -26,7 +27,7 @@ module.exports = (chai) => {
resolve(body);
});

nock.once('error', err => {
nock.on('error', err => {
clearTimeout(timeout);
reject(err);
});
Expand Down
17 changes: 17 additions & 0 deletions test/requested.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ describe('requested assertions', () => {
});
});
});

describe('when a there is an error in the nock', () => {
it('throws', (done) => {
const requestNock = nock(TEST_URL).get('/').reply(200);

const assertion = expect(requestNock).to.have.been.requested;

requestNock.emit('error', new Error('A problem with Nock'))

return assertion
.then(() => done.fail('Should have thrown an error'))
.catch((err) => {
expect(err.message).to.equal('expected Nock to have been requested');
done();
});
});
});
});

describe('.not.requested', () => {
Expand Down
11 changes: 5 additions & 6 deletions test/requestedWith.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ describe('requestedWith() assertions', () => {
const mockArgument = {
test: 12345,
};

const requestNock = nock(TEST_URL).get('/').reply(200);
request({
json: true,
Expand All @@ -135,11 +134,11 @@ describe('requestedWith() assertions', () => {
const assertion = expect(requestNock).not.to.have.been.requestedWith(mockArgument);

return assertion
.then(() => done.fail('Should have thrown an error'))
.catch((err) => {
expect(err.message).to.equal('expected Nock to have not been requested with { test: 12345 }');
done();
});
.then(() => done.fail('Should have thrown an error'))
.catch((err) => {
expect(err.message).to.equal('expected Nock to have not been requested with { test: 12345 }');
done();
});
});
});
});
Expand Down

0 comments on commit aba21b3

Please sign in to comment.