diff --git a/src/classes/TestResult.js b/src/classes/TestResult.js index ed32143..e69729f 100644 --- a/src/classes/TestResult.js +++ b/src/classes/TestResult.js @@ -121,6 +121,11 @@ export default class TestResult extends BubblingEventTarget { } } catch (e) { + // Duck-type assertion errors (Node assert, Chai, etc.) — use their actual/expected for diffs + if ("actual" in e) { + this.actual = e.actual; + this.test.expect = e.expected; + } this.error = e; } } @@ -374,7 +379,8 @@ export default class TestResult extends BubblingEventTarget { } if (!ret.pass) { - if (this.error) { + // Assertion errors have `.actual` — show diff instead of raw error dump + if (this.error && !("actual" in this.error)) { ret.details.push(`Got error ${this.error} ${this.error.stack}`); } diff --git a/tests/errors.js b/tests/errors.js index 039f04e..b613983 100644 --- a/tests/errors.js +++ b/tests/errors.js @@ -229,5 +229,20 @@ export default { }, expect: true, }, + { + name: "AssertionError treated as failure (issue #114)", + skip: typeof globalThis.process === "undefined", + async run () { + let { strict: assert } = await import("node:assert"); + let result = await runTest({ + run () { + assert.equal("hello".toUpperCase(), "hello"); + }, + expect: "HELLO", + }); + return { actual: result.actual, expected: result.test.expect, pass: result.pass }; + }, + expect: { actual: "HELLO", expected: "hello", pass: false }, + }, ], };