Skip to content

Commit

Permalink
fix: ability to register more plugins inside a plugin (#1639)
Browse files Browse the repository at this point in the history
Introduces the ability to chain `use` calls and use the `use` function within a `use` callback
  • Loading branch information
tpluscode authored Jan 7, 2025
1 parent 1b17805 commit 3bc02ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export {AssertionError};
*/
export function use(fn) {
const exports = {
use,
AssertionError,
util,
config,
Expand Down
21 changes: 21 additions & 0 deletions test/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ describe('plugins', function () {
}).to.not.throw();
});

it('nested plugin', function () {
chai.use(function (chai) {
chai.use(plugin);
});
var expect = chai.expect;
expect(expect('').testing).to.equal('successful');
});

it('chained plugin', function () {
chai.use(function (chaiObj) {
Object.defineProperty(chaiObj.Assertion.prototype, 'testing2', {
get() {
return 'bleep bloop';
}
});
}).use(plugin);
var expect = chai.expect;
expect(expect('').testing).to.equal('successful');
expect(expect('').testing2).to.equal('bleep bloop');
});

it('.use detached from chai object', function () {
function anotherPlugin (chai) {
Object.defineProperty(chai.Assertion.prototype, 'moreTesting', {
Expand Down

0 comments on commit 3bc02ee

Please sign in to comment.