fix: add test coverage, correct typo that exposed

This commit is contained in:
Matthew Gabeler-Lee 2018-10-03 18:56:57 -04:00
parent 248d57da4e
commit 1ddac5bddb
No known key found for this signature in database
GPG Key ID: 927112CAD98A0B0E
2 changed files with 33 additions and 1 deletions

View File

@ -713,7 +713,7 @@ function idsHaveDuplicates(ids) {
break;
}
}
if (hasDuplicates === undefined && uniqueIds.length === ids.length) {
if (hasDuplicates === undefined && uniqueIds.size === ids.length) {
hasDuplicates = false;
}
}

View File

@ -559,3 +559,35 @@ describe('util.hasRegExpFlags', function() {
});
});
});
describe('util.idsHaveDuplicates', function() {
context('with string IDs', function() {
it('should be true with a duplicate present', function() {
utils.idsHaveDuplicates(['a', 'b', 'a']).should.be.ok;
});
it('should be false when no duplicates are present', function() {
utils.idsHaveDuplicates(['a', 'b', 'c']).should.not.be.ok;
});
});
context('with numeric IDs', function() {
it('should be true with a duplicate present', function() {
utils.idsHaveDuplicates([1, 2, 1]).should.be.ok;
});
it('should be false when no duplicates are present', function() {
utils.idsHaveDuplicates([1, 2, 3]).should.not.be.ok;
});
});
context('with complex IDs', function() {
it('should be true with a duplicate present', function() {
utils.idsHaveDuplicates(['a', 'b', 'a'].map(id => ({id}))).should.be.ok;
});
it('should be false when no duplicates are present', function() {
utils.idsHaveDuplicates(['a', 'b', 'c'].map(id => ({id}))).should.not.be.ok;
});
});
});