diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..7cafbdb --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +coverage +node_modules \ No newline at end of file diff --git a/index.js b/index.js index c55da9e..fc3fdf9 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ "use strict"; + const equal = require('deep-equal'); module.exports = (chai) => { @@ -26,7 +27,7 @@ module.exports = (chai) => { resolve(body); }); - nock.once('error', err => { + nock.on('error', err => { clearTimeout(timeout); reject(err); }); diff --git a/test/requested.test.js b/test/requested.test.js index c23df15..2216de1 100644 --- a/test/requested.test.js +++ b/test/requested.test.js @@ -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', () => { diff --git a/test/requestedWith.test.js b/test/requestedWith.test.js index 025619f..c4bc526 100644 --- a/test/requestedWith.test.js +++ b/test/requestedWith.test.js @@ -124,7 +124,6 @@ describe('requestedWith() assertions', () => { const mockArgument = { test: 12345, }; - const requestNock = nock(TEST_URL).get('/').reply(200); request({ json: true, @@ -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(); + }); }); }); });