From ff9d48a65907c052541cf17fe582c8eab84e42e4 Mon Sep 17 00:00:00 2001 From: John Vilk Date: Thu, 15 Oct 2015 16:03:27 -0400 Subject: [PATCH] Adding definition of mocha.throwError, with test to cover it. See implementation in Mocha's source code here: https://github.com/mochajs/mocha/blob/c4393c456839d6bf2cbb4abb1cd177010ee06458/support/browser-entry.js#L98 --- mocha/mocha-tests.ts | 4 ++++ mocha/mocha.d.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/mocha/mocha-tests.ts b/mocha/mocha-tests.ts index f90fefaf96..c50f5feab3 100644 --- a/mocha/mocha-tests.ts +++ b/mocha/mocha-tests.ts @@ -249,3 +249,7 @@ function test_run_withOnComplete() { console.log(failures); }); } + +function test_throwError() { + mocha.throwError(new Error("I'm an error!")); +} diff --git a/mocha/mocha.d.ts b/mocha/mocha.d.ts index 88dc359fcc..b4f182aabd 100644 --- a/mocha/mocha.d.ts +++ b/mocha/mocha.d.ts @@ -100,6 +100,12 @@ declare class Mocha { invert(): Mocha; ignoreLeaks(value: boolean): Mocha; checkLeaks(): Mocha; + /** + * Function to allow assertion libraries to throw errors directly into mocha. + * This is useful when running tests in a browser because window.onerror will + * only receive the 'message' attribute of the Error. + */ + throwError(error: Error): void; /** Enables growl support. */ growl(): Mocha; globals(value: string): Mocha;