summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2022-12-20 19:38:42 +0100
committerLinus Groh <mail@linusgroh.de>2023-01-23 09:56:50 +0000
commitfa030d7b9cec8f552f14d0f754fb517227f74ab2 (patch)
tree8ae49f77a51a5dc797851ca643fa0a261c0fa996 /Userland
parent802d9336f01e89c78efaaf827a01e899c6643f39 (diff)
downloadserenity-fa030d7b9cec8f552f14d0f754fb517227f74ab2.zip
LibJS: Clarify more errors in test-common
Without a message these just show 'ExpectationError' even if the check has multiple steps.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Tests/test-common.js25
1 files changed, 20 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Tests/test-common.js b/Userland/Libraries/LibJS/Tests/test-common.js
index 0c177e7280..5251cf79af 100644
--- a/Userland/Libraries/LibJS/Tests/test-common.js
+++ b/Userland/Libraries/LibJS/Tests/test-common.js
@@ -145,15 +145,24 @@ class ExpectationError extends Error {
if (Array.isArray(property)) {
for (let key of property) {
- this.__expect(object !== undefined && object !== null);
+ this.__expect(
+ object !== undefined && object !== null,
+ "got undefined or null as array key"
+ );
object = object[key];
}
} else {
object = object[property];
}
- this.__expect(object !== undefined);
- if (value !== undefined) this.__expect(deepEquals(object, value));
+ this.__expect(object !== undefined, "should not be undefined");
+ if (value !== undefined)
+ this.__expect(
+ deepEquals(object, value),
+ `value does not equal property ${valueToString(object)} vs ${valueToString(
+ value
+ )}`
+ );
});
}
@@ -168,13 +177,19 @@ class ExpectationError extends Error {
toBeInstanceOf(class_) {
this.__doMatcher(() => {
- this.__expect(this.target instanceof class_);
+ this.__expect(
+ this.target instanceof class_,
+ `Expected ${valueToString(this.target)} to be instance of ${class_.name}`
+ );
});
}
toBeNull() {
this.__doMatcher(() => {
- this.__expect(this.target === null);
+ this.__expect(
+ this.target === null,
+ `Expected target to be null got ${valueToString(this.target)}`
+ );
});
}