Skip to content

Commit

Permalink
refactor(Assertion): small edit and improve docs
Browse files Browse the repository at this point in the history
- Rename third parameter of Assertion constructor from `stack` to
  `ssfi` for consistency's sake.
- Add documentation to Assertion constructor explaining what the `object`,
  `message`, and `ssfi` flags are for.
  • Loading branch information
meeber committed Jan 3, 2017
1 parent 82ca613 commit 0c09836
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/chai/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,34 @@ module.exports = function (_chai, util) {
*
* Creates object for chaining.
*
* `Assertion` objects contain metadata in the form of flags. Three flags can
* be assigned during instantiation by passing arguments to this constructor:
*
* - `object`: This flag contains the target of the assertion. For example, in
* the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
* contain `numKittens` so that the `equal` assertion can reference it when
* needed.
*
* - `message`: This flag contains an optional custom error message to be
* prepended to the error message that's generated by the assertion when it
* fails.
*
* - `ssfi`: This flag stands for "start stack function indicator". It
* contains a function reference that serves as the starting point for
* removing frames from the stack trace of the error that's created by the
* assertion when it fails. The goal is to provide a cleaner stack trace to
* end users by removing Chai's internal functions. Note that it only works
* in environments that support `Error.captureStackTrace`, and only when
* `Chai.config.includeStack` hasn't been set to `false`.
*
* @param {Mixed} obj target of the assertion
* @param {String} msg (optional) custom error message
* @param {Function} stack (optional) starting point for removing stack frames
* @api private
*/

function Assertion (obj, msg, stack) {
flag(this, 'ssfi', stack || Assertion);
function Assertion (obj, msg, ssfi) {
flag(this, 'ssfi', ssfi || Assertion);
flag(this, 'object', obj);
flag(this, 'message', msg);

Expand Down

0 comments on commit 0c09836

Please sign in to comment.