Explorar o código

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.
davidot %!s(int64=2) %!d(string=hai) anos
pai
achega
0d8bab82f0
Modificáronse 1 ficheiros con 6 adicións e 4 borrados
  1. 6 4
      Userland/Libraries/LibJS/Tests/test-common.js

+ 6 - 4
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 ?? ""}`
                 );
             });
         }