forked from chaijs/chai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug when asserting some valid ES6 keys
- Resolution of chaijs#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
Showing
10 changed files
with
473 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*! | ||
* Chai - compareByInspect utility | ||
* Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
/*! | ||
* Module dependancies | ||
*/ | ||
|
||
var inspect = require('./inspect'); | ||
|
||
/** | ||
* ### .compareByInspect (mixed, mixed) | ||
* | ||
* To be used as a compareFunction with Array.prototype.sort. Compares elements | ||
* using inspect instead of default behavior of using toString so that Symbols | ||
* and objects with irregular/missing toString can still be sorted without a | ||
* TypeError. | ||
* | ||
* @param {Mixed} first element to compare | ||
* @param {Mixed} second element to compare | ||
* @returns {Number} -1 if 'a' should come before 'b'; otherwise 1 | ||
* @name compareByInspect | ||
* @namespace Utils | ||
* @api public | ||
*/ | ||
|
||
module.exports = function (a, b) { | ||
return inspect(a) < inspect(b) ? -1 : 1; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*! | ||
* Chai - getOwnEnumerableProperties utility | ||
* Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
/*! | ||
* Module dependancies | ||
*/ | ||
|
||
var getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols'); | ||
|
||
/** | ||
* ### .getOwnEnumerableProperties(object) | ||
* | ||
* This allows the retrieval of directly-owned enumerable property names and | ||
* symbols of an. This function is necessary because Object.keys only returns | ||
* enumerable property names, not enumerable property symbols. | ||
* | ||
* @param {Object} object | ||
* @returns {Array} | ||
* @namespace Utils | ||
* @name getOwnEnumerableProperties | ||
* @api public | ||
*/ | ||
|
||
module.exports = function getOwnEnumerableProperties(obj) { | ||
return Object.keys(obj).concat(getOwnEnumerablePropertySymbols(obj)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*! | ||
* Chai - getOwnEnumerablePropertySymbols utility | ||
* Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* ### .getOwnEnumerablePropertySymbols(object) | ||
* | ||
* This allows the retrieval of directly-owned enumerable property symbols of an | ||
* object. This function is necessary because Object.getOwnPropertySymbols | ||
* returns both enumerable and non-enumerable property symbols. | ||
* | ||
* @param {Object} object | ||
* @returns {Array} | ||
* @namespace Utils | ||
* @name getOwnEnumerablePropertySymbols | ||
* @api public | ||
*/ | ||
|
||
module.exports = function getOwnEnumerablePropertySymbols(obj) { | ||
if (typeof Object.getOwnPropertySymbols !== 'function') return []; | ||
|
||
return Object.getOwnPropertySymbols(obj).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(obj, sym).enumerable; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.