frontend/.pnpm-store/v3/files/03/ef5663a67ff9158535872b866d822b207a4f8db0a4053ac99965df3021a88796ac10948e999b04c0db6f1b84c84aa8a265a3298f3efada901b07f915262eca

40 lines
1.3 KiB
Plaintext

"use strict";
var assert = require("chai").assert
, handleException = require("../../lib/resolve-exception");
describe("lib/handle-exception", function () {
it("Should throw TypeError", function () {
try {
handleException(12, "Invalid value");
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "Invalid value");
}
});
it("Should resolve value in default message", function () {
try {
handleException(12, "%v is invalid", {});
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.message, "12 is invalid");
}
});
it("Should support optional values via inputOptions.isOptional", function () {
assert.equal(handleException(null, "%v is invalid", { isOptional: true }, null));
});
it("Should support optional values via inputOptions.default", function () {
// prettier-ignore
assert.equal(handleException(null, "%v is invalid", { "default": "bar" }), "bar");
});
it("Should support custome error message via inputOptions.errorMessage", function () {
try {
handleException(null, "%v is invalid", { errorMessage: "%v is not supported age" });
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.message, "null is not supported age");
}
});
});