Skip to content

Commit

Permalink
style: rename target argument to subject
Browse files Browse the repository at this point in the history
Most assertions use the term "target" to refer to the object under
test, but a few assertions also had a `target` argument, resulting in
an overloaded term that was difficult to document. This commit
renames every `target` argument to `subject`.
  • Loading branch information
meeber committed Apr 8, 2017
1 parent a515ece commit dce6415
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions lib/chai/core/assertions.js
Expand Up @@ -2153,14 +2153,14 @@ module.exports = function (chai, _) {
* @name change
* @alias changes
* @alias Change
* @param {String} target
* @param {String} subject
* @param {String} property name _optional_
* @param {String} message _optional_
* @namespace BDD
* @api public
*/

function assertChanges (target, prop, msg) {
function assertChanges (subject, prop, msg) {
if (msg) flag(this, 'message', msg);
var fn = flag(this, 'object')
, flagMsg = flag(this, 'message')
Expand All @@ -2169,16 +2169,16 @@ module.exports = function (chai, _) {

var initial;
if (!prop) {
new Assertion(target, flagMsg, ssfi, true).is.a('function');
initial = target();
new Assertion(subject, flagMsg, ssfi, true).is.a('function');
initial = subject();
} else {
new Assertion(target, flagMsg, ssfi, true).to.have.property(prop);
initial = target[prop];
new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
initial = subject[prop];
}

fn();

var final = prop === undefined || prop === null ? target() : target[prop];
var final = prop === undefined || prop === null ? subject() : subject[prop];
var msgObj = prop === undefined || prop === null ? initial : '.' + prop;

// This gets flagged because of the .by(delta) assertion
Expand All @@ -2199,7 +2199,7 @@ module.exports = function (chai, _) {
Assertion.addMethod('changes', assertChanges);

/**
* ### .increase(target[, property[, message]])
* ### .increase(subject[, property[, message]])
*
* Asserts that a function increases a numeric object property.
*
Expand All @@ -2217,14 +2217,14 @@ module.exports = function (chai, _) {
* @name increase
* @alias increases
* @alias Increase
* @param {String|Function} target
* @param {String|Function} subject
* @param {String} property name _optional_
* @param {String} message _optional_
* @namespace BDD
* @api public
*/

function assertIncreases (target, prop, msg) {
function assertIncreases (subject, prop, msg) {
if (msg) flag(this, 'message', msg);
var fn = flag(this, 'object')
, flagMsg = flag(this, 'message')
Expand All @@ -2233,19 +2233,19 @@ module.exports = function (chai, _) {

var initial;
if (!prop) {
new Assertion(target, flagMsg, ssfi, true).is.a('function');
initial = target();
new Assertion(subject, flagMsg, ssfi, true).is.a('function');
initial = subject();
} else {
new Assertion(target, flagMsg, ssfi, true).to.have.property(prop);
initial = target[prop];
new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
initial = subject[prop];
}

// Make sure that the target is a number
new Assertion(initial, flagMsg, ssfi, true).is.a('number');

fn();

var final = prop === undefined || prop === null ? target() : target[prop];
var final = prop === undefined || prop === null ? subject() : subject[prop];
var msgObj = prop === undefined || prop === null ? initial : '.' + prop;

flag(this, 'deltaMsgObj', msgObj);
Expand All @@ -2265,7 +2265,7 @@ module.exports = function (chai, _) {
Assertion.addMethod('increases', assertIncreases);

/**
* ### .decrease(target[, property[, message]])
* ### .decrease(subject[, property[, message]])
*
* Asserts that a function decreases a numeric object property.
*
Expand All @@ -2283,14 +2283,14 @@ module.exports = function (chai, _) {
* @name decrease
* @alias decreases
* @alias Decrease
* @param {String|Function} target
* @param {String|Function} subject
* @param {String} property name _optional_
* @param {String} message _optional_
* @namespace BDD
* @api public
*/

function assertDecreases (target, prop, msg) {
function assertDecreases (subject, prop, msg) {
if (msg) flag(this, 'message', msg);
var fn = flag(this, 'object')
, flagMsg = flag(this, 'message')
Expand All @@ -2299,19 +2299,19 @@ module.exports = function (chai, _) {

var initial;
if (!prop) {
new Assertion(target, flagMsg, ssfi, true).is.a('function');
initial = target();
new Assertion(subject, flagMsg, ssfi, true).is.a('function');
initial = subject();
} else {
new Assertion(target, flagMsg, ssfi, true).to.have.property(prop);
initial = target[prop];
new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
initial = subject[prop];
}

// Make sure that the target is a number
new Assertion(initial, flagMsg, ssfi, true).is.a('number');

fn();

var final = prop === undefined || prop === null ? target() : target[prop];
var final = prop === undefined || prop === null ? subject() : subject[prop];
var msgObj = prop === undefined || prop === null ? initial : '.' + prop;

flag(this, 'deltaMsgObj', msgObj);
Expand Down

0 comments on commit dce6415

Please sign in to comment.