|
2 | 2 |
|
3 | 3 | /* eslint no-throw-literal: off */
|
4 | 4 |
|
| 5 | +var sinon = require('sinon'); |
5 | 6 | var Mocha = require('../../lib/mocha');
|
6 | 7 | var Suite = Mocha.Suite;
|
7 | 8 | var Test = Mocha.Test;
|
@@ -29,6 +30,7 @@ describe('a test that throws', function () {
|
29 | 30 | uncaughtHandlers.forEach(function (listener) {
|
30 | 31 | process.on('uncaughtException', listener);
|
31 | 32 | });
|
| 33 | + sinon.restore(); |
32 | 34 | });
|
33 | 35 |
|
34 | 36 | describe('non-extensible', function () {
|
@@ -172,4 +174,35 @@ describe('a test that throws', function () {
|
172 | 174 | runner.run();
|
173 | 175 | });
|
174 | 176 | });
|
| 177 | + |
| 178 | + describe('stack', function() { |
| 179 | + it('should include the stack when throwing async', function(done) { |
| 180 | + var test = new Test('im async and throw null async', function(done2) { |
| 181 | + process.nextTick(function throwError() { |
| 182 | + throw new Error('test error'); |
| 183 | + }); |
| 184 | + }); |
| 185 | + suite.addTest(test); |
| 186 | + runner = new Runner(suite); |
| 187 | + sinon.stub(runner, 'fail'); |
| 188 | + |
| 189 | + runner.on(EVENT_RUN_END, function() { |
| 190 | + try { |
| 191 | + expect(runner.fail, 'to have all calls satisfying', [ |
| 192 | + expect.it('to be a', Runnable), |
| 193 | + expect.it('to be an', Error).and('to satisfy', { |
| 194 | + message: /test error/i, |
| 195 | + stack: /throwError/i, |
| 196 | + uncaught: true |
| 197 | + }) |
| 198 | + ]).and('was called once'); |
| 199 | + } catch (err) { |
| 200 | + return done(err); |
| 201 | + } |
| 202 | + |
| 203 | + done(); |
| 204 | + }); |
| 205 | + runner.run(); |
| 206 | + }); |
| 207 | + }); |
175 | 208 | });
|
0 commit comments