1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:47:45 +00:00

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

View file

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