1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

LibJS: Clarify more errors in test-common

Without a message these just show 'ExpectationError' even if the check
has multiple steps.
This commit is contained in:
davidot 2022-12-20 19:38:42 +01:00 committed by Linus Groh
parent 802d9336f0
commit fa030d7b9c

View file

@ -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)}`
);
});
}