diff options
author | davidot <davidot@serenityos.org> | 2022-10-12 01:34:31 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-23 15:48:45 +0200 |
commit | 80f23abd0abd63aa6f2ad871cf10092d567d8535 (patch) | |
tree | a5f8d2293bc6d2dbddec4fa0a0fcad0691196ff7 /Userland/Libraries/LibJS/Tests | |
parent | e3de568a455ff12778146560b122e5a1945106fb (diff) | |
download | serenity-80f23abd0abd63aa6f2ad871cf10092d567d8535.zip |
LibJS: Add descriptive output to test-commons expect().toThrow()
This (and still some other methods) just say Expectation error leaving
the user completely in the dark whether the method threw at all.
And since we have nice function printing now we can just toString the
function since most are lambda's.
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/test-common.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Tests/test-common.js b/Userland/Libraries/LibJS/Tests/test-common.js index 3f5e51d24b..c1979d3cec 100644 --- a/Userland/Libraries/LibJS/Tests/test-common.js +++ b/Userland/Libraries/LibJS/Tests/test-common.js @@ -306,14 +306,30 @@ class ExpectationError extends Error { threw = false; } catch (e) { if (typeof value === "string") { - this.__expect(e.message.includes(value)); + this.__expect( + e.message.includes(value), + `Expected ${this.target.toString()} to throw and message to include "${value}" but message "${ + e.message + }" did not contain it` + ); } else if (typeof value === "function") { - this.__expect(e instanceof value); + this.__expect( + e instanceof value, + `Expected ${this.target.toString()} to throw and be of type ${value} but it threw ${e}` + ); } else if (typeof value === "object") { - this.__expect(e.message === value.message); + this.__expect( + e.message === value.message, + `Expected ${this.target.toString()} to throw and message to be ${value} but it threw with message ${ + e.message + }` + ); } } - this.__expect(threw); + this.__expect( + threw, + `Expected ${this.target.toString()} to throw but it didn't throw anything` + ); }); } |