UNPKG

cli-testing-library

Version:

Simple and complete CLI testing utilities that encourage good testing practices.

32 lines (31 loc) 1.1 kB
import { getDefaultNormalizer } from "../matches.js"; import { checkCliInstance, getMessage } from "./utils.js"; function toHaveErrorMessage(testInstance, checkWith) { checkCliInstance(testInstance, toHaveErrorMessage, this); const expectsErrorMessage = checkWith !== void 0; const errormessage = getDefaultNormalizer()( testInstance.stderrArr.map((obj) => obj.contents).join("\n") ); return { pass: expectsErrorMessage ? checkWith instanceof RegExp ? checkWith.test(errormessage) : this.equals(errormessage, checkWith) : Boolean(testInstance.stderrArr.length), message: () => { const to = this.isNot ? "not to" : "to"; return getMessage( this, this.utils.matcherHint( `${this.isNot ? ".not" : ""}.toHaveErrorMessage`, "instance", "" ), `Expected the instance ${to} have error message`, this.utils.printExpected(checkWith), "Received", this.utils.printReceived(errormessage) ); } }; } export { toHaveErrorMessage }; //# sourceMappingURL=to-have-errormessage.js.map