Bladeren bron

LibJS: Clarify more errors in test-common

Without a message these just show 'ExpectationError' even if the check
has multiple steps.
davidot 2 jaren geleden
bovenliggende
commit
fa030d7b9c
1 gewijzigde bestanden met toevoegingen van 20 en 5 verwijderingen
  1. 20 5
      Userland/Libraries/LibJS/Tests/test-common.js

+ 20 - 5
Userland/Libraries/LibJS/Tests/test-common.js

@@ -145,15 +145,24 @@ class ExpectationError extends Error {
 
 
                 if (Array.isArray(property)) {
                 if (Array.isArray(property)) {
                     for (let key of 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];
                         object = object[key];
                     }
                     }
                 } else {
                 } else {
                     object = object[property];
                     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_) {
         toBeInstanceOf(class_) {
             this.__doMatcher(() => {
             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() {
         toBeNull() {
             this.__doMatcher(() => {
             this.__doMatcher(() => {
-                this.__expect(this.target === null);
+                this.__expect(
+                    this.target === null,
+                    `Expected target to be null got ${valueToString(this.target)}`
+                );
             });
             });
         }
         }