From 30c7ffb8005937707ee894623d28b054eb621fd8 Mon Sep 17 00:00:00 2001 From: Peter Rust Date: Wed, 12 Jun 2019 09:42:13 -0700 Subject: [PATCH] Attempt at testing (failing due to uncaught exception) --- karma.conf.js | 6 ++++- .../uncaught-exception.spec.mjs | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/browser-specific/uncaught-exception.spec.mjs diff --git a/karma.conf.js b/karma.conf.js index 82e934bbc7..dedb4a9e68 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -143,7 +143,11 @@ module.exports = config => { pattern: 'test/browser-specific/fixtures/esm.fixture.mjs', type: 'module' }, - {pattern: 'test/browser-specific/esm.spec.mjs', type: 'module'} + {pattern: 'test/browser-specific/esm.spec.mjs', type: 'module'}, + { + pattern: 'test/browser-specific/uncaught-exception.spec.mjs', + type: 'module' + } ]; break; default: diff --git a/test/browser-specific/uncaught-exception.spec.mjs b/test/browser-specific/uncaught-exception.spec.mjs new file mode 100644 index 0000000000..54b852f875 --- /dev/null +++ b/test/browser-specific/uncaught-exception.spec.mjs @@ -0,0 +1,27 @@ +import '/base/mocha.js'; + +var Mocha = window.Mocha; +var Suite = Mocha.Suite; +var Runner = Mocha.Runner; + +mocha.allowUncaught() + +it('should include the stack of uncaught exceptions', function(done) { + var suite = new Suite('Suite', 'root'); + var runner = new Runner(suite); + runner.allowUncaught = true; + var err; + runner.fail = function(e) { + err = e; + }; + + setTimeout(function throwTestError() { + throw new Error('test error'); + }, 1); + + setTimeout(function() { + expect(err, 'to be an', Error); + expect(err.stack, 'to contain', 'at throwTestError') + done(); + }, 2); +});