-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
getAllFlags
with transferFlags
utility.
This will help more directly with #66 and with chaijs/chai-as-promised#5.
- Loading branch information
Showing
4 changed files
with
72 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
/*! | ||
* Chai - transferFlags utility | ||
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* ### transferFlags(assertion, object, includeAll = true) | ||
* | ||
* Transfer all the flags for `assertion` to `object`. If | ||
* `includeAll` is set to `false`, then the base Chai | ||
* assertion flags (namely `object`, `ssfi`, and `message`) | ||
* will not be transferred. | ||
* | ||
* | ||
* var newAssertion = new Assertion(); | ||
* utils.transferFlags(assertion, newAssertion); | ||
* | ||
* var anotherAsseriton = new Assertion(myObj); | ||
* utils.transferFlags(assertion, anotherAssertion, false); | ||
* | ||
* @param {Assertion} assertion the assertion to transfer the flags from | ||
* @param {Object} object the object to transfer the flags too; usually a new assertion | ||
* @param {Boolean} includeAll | ||
* @name getAllFlags | ||
* @api private | ||
*/ | ||
|
||
module.exports = function (assertion, object, includeAll) { | ||
var flags = assertion.__flags || (assertion.__flags = Object.create(null)); | ||
|
||
if (!object.__flags) { | ||
object.__flags = Object.create(null); | ||
} | ||
|
||
includeAll = arguments.length === 3 ? includeAll : true; | ||
|
||
for (var flag in flags) { | ||
if (includeAll || | ||
(flag !== 'object' && flag !== 'ssfi' && flag != 'message')) { | ||
object.__flags[flag] = flags[flag]; | ||
} | ||
} | ||
}; |
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