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:
parent
c5730ed6a3
commit
0718f216af
10 changed files with 112 additions and 118 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue