Repository navigation
Replies: 1 comment
|
Yes. A plugin receives Chai's For example, this exposes the same check through both interfaces: import * as chai from "chai";
function evenPlugin(chai) {
chai.Assertion.addMethod("even", function () {
this.assert(
Number.isInteger(this._obj) && this._obj % 2 === 0,
"expected #{this} to be an even integer",
"expected #{this} not to be an even integer"
);
});
chai.assert.isEven = function (value, message) {
new chai.Assertion(value, message, chai.assert.isEven)
.to.be.even();
};
}
chai.use(evenPlugin);
chai.assert.isEven(2);
chai.expect(2).to.be.even();The wrapper passes the optional message and delegates to the existing assertion, so failures remain I tested this with Chai 4.3.10 and 6.2.2, including odd values, non-integers, a custom message, and negated See Core Plugin Concepts for plugin registration and assertion construction. Chai's own |
Uh oh!
There was an error while loading. Please reload this page.
There is a documentation of extending the
expectassertion APIs.Is there a way (and documentation) how to plugin custom assertions into
assertAPI?All reactions