Skip to content

Commit 3bc02ee

Browse files
authored
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
1 parent 1b17805 commit 3bc02ee

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/chai.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export {AssertionError};
2929
*/
3030
export function use(fn) {
3131
const exports = {
32+
use,
3233
AssertionError,
3334
util,
3435
config,

test/plugins.js

+21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ describe('plugins', function () {
2424
}).to.not.throw();
2525
});
2626

27+
it('nested plugin', function () {
28+
chai.use(function (chai) {
29+
chai.use(plugin);
30+
});
31+
var expect = chai.expect;
32+
expect(expect('').testing).to.equal('successful');
33+
});
34+
35+
it('chained plugin', function () {
36+
chai.use(function (chaiObj) {
37+
Object.defineProperty(chaiObj.Assertion.prototype, 'testing2', {
38+
get() {
39+
return 'bleep bloop';
40+
}
41+
});
42+
}).use(plugin);
43+
var expect = chai.expect;
44+
expect(expect('').testing).to.equal('successful');
45+
expect(expect('').testing2).to.equal('bleep bloop');
46+
});
47+
2748
it('.use detached from chai object', function () {
2849
function anotherPlugin (chai) {
2950
Object.defineProperty(chai.Assertion.prototype, 'moreTesting', {

0 commit comments

Comments
 (0)