1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

LibJS: Add assertThrowsError() test function

This commit is contained in:
Linus Groh 2020-04-19 23:01:45 +01:00 committed by Andreas Kling
parent c5730ed6a3
commit 0718f216af
10 changed files with 112 additions and 118 deletions

View file

@ -14,3 +14,18 @@ function assert(value) {
function assertNotReached() {
throw new AssertionError("assertNotReached() was reached!");
}
function assertThrowsError(testFunction, options) {
try {
testFunction();
assertNotReached();
} catch (e) {
if (options.error !== undefined)
assert(e instanceof options.error);
if (options.name !== undefined)
assert(e.name === options.name);
if (options.message !== undefined)
assert(e.message === options.message);
}
}