diff --git a/src/assert.ts b/src/assert.ts index a05c062..d020399 100644 --- a/src/assert.ts +++ b/src/assert.ts @@ -5,9 +5,13 @@ export type { Equals } from "./Equals"; /** @see */ export class AssertionError extends Error { + originalMessage?: string; + constructor(msg: string | undefined) { super(`Wrong assertion encountered` + (!msg ? "" : `: "${msg}"`)); + this.originalMessage = msg; + Object.setPrototypeOf(this, new.target.prototype); if (!this.stack) { diff --git a/test/assertIs.ts b/test/assertIs.ts index 3c8855c..6f6decf 100644 --- a/test/assertIs.ts +++ b/test/assertIs.ts @@ -122,3 +122,12 @@ scope: { console.log("PASS"); } } + +/** + * `AssertionError` should store the original message in the `originalMessage` property. + */ +{ + const error = new AssertionError("message"); + assert(error.originalMessage === "message"); + console.log("PASS"); +}