Skip to content

Commit ea1ee6a

Browse files
committedNov 25, 2018
Support symbol properties in contain()
1 parent b6907ac commit ea1ee6a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎lib/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ exports.contain = function (ref, values, options) {
336336
!Array.isArray(values)) {
337337

338338
valuePairs = values;
339-
values = Object.keys(values);
339+
const symbols = Object.getOwnPropertySymbols(values).filter(Object.prototype.propertyIsEnumerable.bind(values));
340+
values = [...Object.keys(values), ...symbols];
340341
}
341342
else {
342343
values = [].concat(values);
@@ -411,7 +412,7 @@ exports.contain = function (ref, values, options) {
411412
}
412413
}
413414
else {
414-
const keys = Object.getOwnPropertyNames(ref);
415+
const keys = Reflect.ownKeys(ref);
415416
for (let i = 0; i < keys.length; ++i) {
416417
const key = keys[i];
417418
const pos = values.indexOf(key);

‎test/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,18 @@ describe('contain()', () => {
17541754
expect(Hoek.contain(foo, { 'a': 1, 'b': 2, 'c': 3 }, { only: true })).to.be.true();
17551755
}
17561756
});
1757+
1758+
it('supports symbols', () => {
1759+
1760+
const sym = Symbol();
1761+
1762+
expect(Hoek.contain([sym], sym)).to.be.true();
1763+
expect(Hoek.contain({ [sym]: 1 }, sym)).to.be.true();
1764+
expect(Hoek.contain({ [sym]: 1, a: 2 }, { [sym]: 1 })).to.be.true();
1765+
1766+
expect(Hoek.contain([sym], Symbol())).to.be.false();
1767+
expect(Hoek.contain({ [sym]: 1 }, Symbol())).to.be.false();
1768+
});
17571769
});
17581770

17591771
describe('flatten()', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.