Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types #1557

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions lib/chai/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {config} from './config.js';
import {AssertionError} from 'assertion-error';
import * as util from './utils/index.js';

/*!
/**
* Assertion Constructor
*
* Creates object for chaining.
Expand Down Expand Up @@ -42,10 +42,10 @@ import * as util from './utils/index.js';
*
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
*
* @param {Mixed} obj target of the assertion
* @param {String} msg (optional) custom error message
* @param {Function} ssfi (optional) starting point for removing stack frames
* @param {Boolean} lockSsfi (optional) whether or not the ssfi flag is locked
* @param {unknown} obj target of the assertion
* @param {String} [msg] custom error message
* @param {Function} [ssfi] starting point for removing stack frames
* @param {Boolean} [lockSsfi] whether or not the ssfi flag is locked
* @api private
*/

Expand Down Expand Up @@ -81,26 +81,52 @@ Object.defineProperty(Assertion, 'showDiff', {
}
});

/**
* @param {string} name
* @param {Function} fn
*/
Assertion.addProperty = function (name, fn) {
util.addProperty(this.prototype, name, fn);
};

/**
* @param {string} name
* @param {Function} fn
*/
Assertion.addMethod = function (name, fn) {
util.addMethod(this.prototype, name, fn);
};

/**
* @param {string} name
* @param {Function} fn
* @param {Function} chainingBehavior
*/
Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
};

/**
* @param {string} name
* @param {Function} fn
*/
Assertion.overwriteProperty = function (name, fn) {
util.overwriteProperty(this.prototype, name, fn);
};

/**
* @param {string} name
* @param {Function} fn
*/
Assertion.overwriteMethod = function (name, fn) {
util.overwriteMethod(this.prototype, name, fn);
};

/**
* @param {string} name
* @param {Function} fn
* @param {Function} chainingBehavior
*/
Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
};
Expand All @@ -111,12 +137,12 @@ Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
*
* @name assert
* @param {Philosophical} expression to be tested
* @param {String|Function} message or function that returns message to display if expression fails
* @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
* @param {Mixed} expected value (remember to check for negation)
* @param {Mixed} actual (optional) will default to `this.obj`
* @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
* @param {unknown} expr expression to be tested
* @param {String|Function} msg message or function that returns message to display if expression fails
* @param {String|Function} negateMsg negatedMessage or function that returns negatedMessage to display if negated expression fails
* @param {unknown} [expected] value (remember to check for negation)
* @param {unknown} [_actual] will default to `this.obj`
* @param {Boolean} [showDiff] when set to `true`, assert will display a diff in addition to the message if expression fails
* @api private
*/

Expand All @@ -127,12 +153,13 @@ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual,
if (true !== config.showDiff) showDiff = false;

if (!ok) {
msg = util.getMessage(this, arguments);
msg = util.getMessage(this, msg, negateMsg, expected, _actual);
var actual = util.getActual(this, arguments);
var assertionErrorObjectProperties = {
actual: actual
, expected: expected
, showDiff: showDiff
, operator: undefined
};

var operator = util.getOperator(this, arguments);
Expand Down
Loading
Loading