Skip to content

Commit

Permalink
added test and fix for duplicate globals
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalpp committed May 28, 2019
1 parent ffbcbf6 commit 74a9896
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/mocha.js
Expand Up @@ -553,7 +553,13 @@ Mocha.prototype._growl = growl.notify;
Mocha.prototype.globals = function(globals) {
this.options.globals = (this.options.globals || [])
.concat(globals)
.filter(Boolean);
.filter(Boolean)
.reduce(function dedupe(memo, item) {
if (memo.indexOf(item) < 0) {
memo.push(item);
}
return memo;
}, []);
return this;
};

Expand Down
8 changes: 8 additions & 0 deletions test/unit/mocha.spec.js
Expand Up @@ -174,6 +174,14 @@ describe('Mocha', function() {
expect(mocha.options.globals, 'to contain', elem, elem2);
expect(mocha.options.globals, 'to have length', elems.length);
});

it('should not have duplicates', function() {
var mocha = new Mocha({globals: [elem, elem2]});
var elems = [elem, elem2];
mocha.globals(elems);
expect(mocha.options.globals, 'to contain', elem, elem2);
expect(mocha.options.globals, 'to have length', elems.length);
});
});
});

Expand Down

0 comments on commit 74a9896

Please sign in to comment.