LibJS: Add custom details to toBe{True, False} shown on failure

Any test with multiple expect(...).toBe{True, False} checks is very hard
to debug.
This commit is contained in:
davidot 2022-12-20 19:41:23 +01:00 committed by Linus Groh
parent fa030d7b9c
commit 0d8bab82f0
Notes: sideshowbarker 2024-07-17 09:49:33 +09:00

View file

@ -214,24 +214,26 @@ class ExpectationError extends Error {
});
}
toBeTrue() {
toBeTrue(customDetails = undefined) {
this.__doMatcher(() => {
this.__expect(
this.target === true,
() =>
`toBeTrue: expected target to be true, got _${valueToString(this.target)}_`
`toBeTrue: expected target to be true, got _${valueToString(this.target)}_${
customDetails ? ` (${customDetails})` : ""
}`
);
});
}
toBeFalse() {
toBeFalse(customDetails = undefined) {
this.__doMatcher(() => {
this.__expect(
this.target === false,
() =>
`toBeFalse: expected target to be false, got _${valueToString(
this.target
)}_`
)}_${customDetails ?? ""}`
);
});
}