Skip to content

Commit

Permalink
Fix bug when asserting some valid ES6 keys
Browse files Browse the repository at this point in the history
- Resolution of chaijs/chai#674
- Add compareByInspect utility for use with assertKeys sorts
- Add getOwnEnumerableProperties utility
- Add getOwnEnumerablePropertySymbols utility
- Add Symbol support to the inspect utility
- Add tests to utilities, should, expect, and assert
  • Loading branch information
meeber committed Apr 11, 2016
1 parent c0dfc2d commit f3195c7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ module.exports = function (chai, _) {
}

} else {
actual = Object.keys(obj);
actual = _.getOwnEnumerableProperties(obj);

switch (_.type(keys)) {
case 'array':
Expand All @@ -1184,7 +1184,10 @@ module.exports = function (chai, _) {
keys = Array.prototype.slice.call(arguments);
}

keys = keys.map(String);
// Only stringify non-Symbols because Symbols would become "Symbol()"
keys = keys.map(function (val) {
return typeof val === 'symbol' ? val : String(val);
});
}

if (!keys.length) throw new Error('keys required');
Expand Down Expand Up @@ -1248,8 +1251,8 @@ module.exports = function (chai, _) {
ok
, 'expected #{this} to ' + str
, 'expected #{this} to not ' + str
, expected.slice(0).sort()
, actual.sort()
, expected.slice(0).sort(_.compareByInspect)
, actual.sort(_.compareByInspect)
, true
);
}
Expand Down

0 comments on commit f3195c7

Please sign in to comment.