@kitmi/utils
Version:
A JavaScript utility library for both server and browser
40 lines (39 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _each = /*#__PURE__*/ _interop_require_default(require("lodash/each"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
/**
* Test if an async function throws an error
* @param {Function} fn - Function (async) that should throw an error
* @param {*} error
*/ const shouldThrow_ = async (fn, error, details)=>{
try {
await fn();
// eslint-disable-next-line no-undef
should.not.exist('here');
} catch (e) {
if (details) {
(0, _each.default)(details, (value, key)=>{
should.exist(e[key]);
e[key].should.eql(value);
});
}
(()=>{
throw e;
}).should.throws(error);
}
};
const _default = shouldThrow_;
//# sourceMappingURL=testShouldThrow_.js.map