Merge pull request #23984 from cghawthorne/master

tape: Add support for custom Error subclasses in throws
This commit is contained in:
Armando Aguirre
2018-03-06 17:47:58 -08:00
committed by GitHub
2 changed files with 12 additions and 2 deletions

View File

@@ -193,13 +193,13 @@ declare namespace tape {
* expected, if present, must be a RegExp or Function, which is used to test the exception object.
*/
throws(fn: () => void, msg?: string): void;
throws(fn: () => void, exceptionExpected: RegExp | (() => void), msg?: string): void;
throws(fn: () => void, exceptionExpected: RegExp | Function, msg?: string): void;
/**
* Assert that the function call fn() does not throw an exception.
*/
doesNotThrow(fn: () => void, msg?: string): void;
doesNotThrow(fn: () => void, exceptionExpected: RegExp | (() => void), msg?: string): void;
doesNotThrow(fn: () => void, exceptionExpected: RegExp | Function, msg?: string): void;
/**
* Print a message without breaking the tap output.

View File

@@ -28,6 +28,12 @@ rs = tape.createStream(sopts);
var htest: typeof tape;
htest = tape.createHarness();
class CustomException extends Error {
constructor(message?: string) {
super(message);
}
}
tape(name, (test: tape.Test) => {
@@ -146,11 +152,15 @@ tape(name, (test: tape.Test) => {
test.throws(fn, msg);
test.throws(fn, exceptionExpected);
test.throws(fn, exceptionExpected, msg);
test.throws(fn, CustomException);
test.throws(fn, CustomException, msg);
test.doesNotThrow(fn);
test.doesNotThrow(fn, msg);
test.doesNotThrow(fn, exceptionExpected);
test.doesNotThrow(fn, exceptionExpected, msg);
test.doesNotThrow(fn, CustomException);
test.doesNotThrow(fn, CustomException, msg);
test.test(name, (st) => {
t = st;