From 0d8bab82f01cb85709dea182fc288aadb7215811 Mon Sep 17 00:00:00 2001 From: davidot Date: Tue, 20 Dec 2022 19:41:23 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibJS/Tests/test-common.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Tests/test-common.js b/Userland/Libraries/LibJS/Tests/test-common.js index 5251cf79af..1ecfa8c0b6 100644 --- a/Userland/Libraries/LibJS/Tests/test-common.js +++ b/Userland/Libraries/LibJS/Tests/test-common.js @@ -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 ?? ""}` ); }); }