From 3bc02eee4612a5245a675e656340e21813a7be4c Mon Sep 17 00:00:00 2001 From: Tomasz Pluskiewicz Date: Tue, 7 Jan 2025 21:56:52 +0100 Subject: [PATCH] fix: ability to register more plugins inside a plugin (#1639) Introduces the ability to chain `use` calls and use the `use` function within a `use` callback --- lib/chai.js | 1 + test/plugins.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/chai.js b/lib/chai.js index 507d9c76..734e3725 100644 --- a/lib/chai.js +++ b/lib/chai.js @@ -29,6 +29,7 @@ export {AssertionError}; */ export function use(fn) { const exports = { + use, AssertionError, util, config, diff --git a/test/plugins.js b/test/plugins.js index 4db1f44d..c9c013cc 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -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', {