From fa030d7b9cec8f552f14d0f754fb517227f74ab2 Mon Sep 17 00:00:00 2001 From: davidot Date: Tue, 20 Dec 2022 19:38:42 +0100 Subject: LibJS: Clarify more errors in test-common Without a message these just show 'ExpectationError' even if the check has multiple steps. --- Userland/Libraries/LibJS/Tests/test-common.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'Userland/Libraries/LibJS') 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)}` + ); }); } -- cgit v1.2.3