diff --git a/test.js b/test.js index 77eac58..bb4aa8c 100644 --- a/test.js +++ b/test.js @@ -994,6 +994,34 @@ describe('simple', function () { }) }) + describe('when mock rejectsWith', function () { + + it('and mock is called at a later time then no UnhandledPromiseRejectionWarning and PromiseRejectionHandledWarning occurs', function (done) { + var warnings = [] + function logWarning () { + var message = arguments.length === 2 ? 'Unhandled promise rejection' : 'Promise rejection was handled asynchronously' + warnings.push(message) + } + process.on('rejectionHandled', logWarning) + process.on('unhandledRejection', logWarning) + + var mock = simple.mock().rejectWith(new Error('from rejectWith')) + setTimeout(function () { + mock().then(function () { + return Promise.reject('Mock should have been rejected') + }, function () { + assert.equal(warnings.length, 0, 'Warnings "' + warnings.join('", "') + '"') + }) + .then(done, done) + .then(function () { + process.removeListener('rejectionHandled', logWarning) + process.removeListener('unhandledRejection', logWarning) + }) + }) + }) + + }) + describe('#noLoop', function () { it('should disable looping', function () {