cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
32 lines (31 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const matches = require("../matches.cjs");
const utils = require("./utils.cjs");
function toHaveErrorMessage(testInstance, checkWith) {
utils.checkCliInstance(testInstance, toHaveErrorMessage, this);
const expectsErrorMessage = checkWith !== void 0;
const errormessage = matches.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 utils.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)
);
}
};
}
exports.toHaveErrorMessage = toHaveErrorMessage;
//# sourceMappingURL=to-have-errormessage.cjs.map