Skip to content

Commit

Permalink
Merge pull request #516 from keithamus/release-3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Sep 11, 2015
2 parents cf9f5d9 + 13a9009 commit df954cc
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 36 deletions.
181 changes: 147 additions & 34 deletions chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var used = []
* Chai version
*/

exports.version = '3.2.0';
exports.version = '3.3.0';

/*!
* Assertion Error
Expand Down Expand Up @@ -503,7 +503,7 @@ module.exports = function (chai, _) {
for (var k in val) subset[k] = obj[k];
expected = _.eql(subset, val);
} else {
expected = obj && ~obj.indexOf(val);
expected = (obj != undefined) && ~obj.indexOf(val);
}
this.assert(
expected
Expand Down Expand Up @@ -681,17 +681,8 @@ module.exports = function (chai, _) {
*/

Assertion.addProperty('empty', function () {
var obj = flag(this, 'object')
, expected = obj;

if (Array.isArray(obj) || 'string' === typeof object) {
expected = obj.length;
} else if (typeof obj === 'object') {
expected = Object.keys(obj).length;
}

this.assert(
!expected
Object.keys(Object(flag(this, 'object'))).length === 0
, 'expected #{this} to be empty'
, 'expected #{this} not to be empty'
);
Expand Down Expand Up @@ -1727,7 +1718,7 @@ module.exports = function (chai, _) {
, result
);
}

Assertion.addMethod('satisfy', satisfy);
Assertion.addMethod('satisfies', satisfy);

Expand Down Expand Up @@ -1937,7 +1928,7 @@ module.exports = function (chai, _) {
/**
* ### .extensible
*
* Asserts that the target is extensible (can have new properties added to
* Asserts that the target is extensible (can have new properties added to
* it).
*
* var nonExtensibleObject = Object.preventExtensions({});
Expand All @@ -1956,8 +1947,22 @@ module.exports = function (chai, _) {
Assertion.addProperty('extensible', function() {
var obj = flag(this, 'object');

// In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
// In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
// The following provides ES6 behavior when a TypeError is thrown under ES5.

var isExtensible;

try {
isExtensible = Object.isExtensible(obj);
} catch (err) {
if (err instanceof TypeError) isExtensible = false;
else throw err;
}

this.assert(
Object.isExtensible(obj)
isExtensible
, 'expected #{this} to be extensible'
, 'expected #{this} to not be extensible'
);
Expand All @@ -1983,8 +1988,22 @@ module.exports = function (chai, _) {
Assertion.addProperty('sealed', function() {
var obj = flag(this, 'object');

// In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
// In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
// The following provides ES6 behavior when a TypeError is thrown under ES5.

var isSealed;

try {
isSealed = Object.isSealed(obj);
} catch (err) {
if (err instanceof TypeError) isSealed = true;
else throw err;
}

this.assert(
Object.isSealed(obj)
isSealed
, 'expected #{this} to be sealed'
, 'expected #{this} to not be sealed'
);
Expand All @@ -2008,13 +2027,26 @@ module.exports = function (chai, _) {
Assertion.addProperty('frozen', function() {
var obj = flag(this, 'object');

// In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
// In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
// The following provides ES6 behavior when a TypeError is thrown under ES5.

var isFrozen;

try {
isFrozen = Object.isFrozen(obj);
} catch (err) {
if (err instanceof TypeError) isFrozen = true;
else throw err;
}

this.assert(
Object.isFrozen(obj)
isFrozen
, 'expected #{this} to be frozen'
, 'expected #{this} to not be frozen'
);
});

};

},{}],6:[function(require,module,exports){
Expand Down Expand Up @@ -2245,16 +2277,16 @@ module.exports = function (chai, util) {
new Assertion(act, msg).to.not.eql(exp);
};

/**
* ### .isTrue(value, [message])
/**
* ### .isAbove(valueToCheck, valueToBeAbove, [message])
*
* Asserts that `value` is true.
* Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`
*
* var teaServed = true;
* assert.isTrue(teaServed, 'the tea has been served');
* assert.isAbove(5, 2, '5 is strictly greater than 2');
*
* @name isTrue
* @param {Mixed} value
* @name isAbove
* @param {Mixed} valueToCheck
* @param {Mixed} valueToBeAbove
* @param {String} message
* @api public
*/
Expand All @@ -2264,21 +2296,22 @@ module.exports = function (chai, util) {
};

/**
* ### .isAbove(valueToCheck, valueToBeAbove, [message])
* ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
*
* Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`
* Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`
*
* assert.isAbove(5, 2, '5 is strictly greater than 2');
* assert.isAtLeast(5, 2, '5 is greater or equal to 2');
* assert.isAtLeast(3, 3, '3 is greater or equal to 3');
*
* @name isAbove
* @name isAtLeast
* @param {Mixed} valueToCheck
* @param {Mixed} valueToBeAbove
* @param {Mixed} valueToBeAtLeast
* @param {String} message
* @api public
*/

assert.isBelow = function (val, blw, msg) {
new Assertion(val, msg).to.be.below(blw);
assert.isAtLeast = function (val, atlst, msg) {
new Assertion(val, msg).to.be.least(atlst);
};

/**
Expand All @@ -2295,10 +2328,65 @@ module.exports = function (chai, util) {
* @api public
*/

assert.isBelow = function (val, blw, msg) {
new Assertion(val, msg).to.be.below(blw);
};

/**
* ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
*
* Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`
*
* assert.isAtMost(3, 6, '3 is less than or equal to 6');
* assert.isAtMost(4, 4, '4 is less than or equal to 4');
*
* @name isAtMost
* @param {Mixed} valueToCheck
* @param {Mixed} valueToBeAtMost
* @param {String} message
* @api public
*/

assert.isAtMost = function (val, atmst, msg) {
new Assertion(val, msg).to.be.most(atmst);
};

/**
* ### .isTrue(value, [message])
*
* Asserts that `value` is true.
*
* var teaServed = true;
* assert.isTrue(teaServed, 'the tea has been served');
*
* @name isTrue
* @param {Mixed} value
* @param {String} message
* @api public
*/

assert.isTrue = function (val, msg) {
new Assertion(val, msg).is['true'];
};

/**
* ### .isNotTrue(value, [message])
*
* Asserts that `value` is not true.
*
* var tea = 'tasty chai';
* assert.isNotTrue(tea, 'great, time for tea!');
*
* @name isNotTrue
* @param {Mixed} value
* @param {String} message
* @api public
*/

assert.isNotTrue = function (val, msg) {
new Assertion(val, msg).to.not.equal(true);
};

/**
* ### .isFalse(value, [message])
*
Expand All @@ -2317,6 +2405,24 @@ module.exports = function (chai, util) {
new Assertion(val, msg).is['false'];
};

/**
* ### .isNotFalse(value, [message])
*
* Asserts that `value` is not false.
*
* var tea = 'tasty chai';
* assert.isNotFalse(tea, 'great, time for tea!');
*
* @name isNotFalse
* @param {Mixed} value
* @param {String} message
* @api public
*/

assert.isNotFalse = function (val, msg) {
new Assertion(val, msg).to.not.equal(false);
};

/**
* ### .isNull(value, [message])
*
Expand Down Expand Up @@ -3757,6 +3863,9 @@ module.exports = function (ctx, name, method) {
* MIT Licensed
*/

var config = require('../config');
var flag = require('./flag');

/**
* ### addProperty (ctx, name, getter)
*
Expand Down Expand Up @@ -3784,15 +3893,19 @@ module.exports = function (ctx, name, method) {

module.exports = function (ctx, name, getter) {
Object.defineProperty(ctx, name,
{ get: function () {
{ get: function addProperty() {
var old_ssfi = flag(this, 'ssfi');
if (old_ssfi && config.includeStack === false)
flag(this, 'ssfi', addProperty);

var result = getter.call(this);
return result === undefined ? this : result;
}
, configurable: true
});
};

},{}],12:[function(require,module,exports){
},{"../config":4,"./flag":12}],12:[function(require,module,exports){
/*!
* Chai - flag utility
* Copyright(c) 2012-2014 Jake Luer <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion lib/chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var used = []
* Chai version
*/

exports.version = '3.2.0';
exports.version = '3.3.0';

/*!
* Assertion Error
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"Veselin Todorov <[email protected]>",
"John Firebaugh <[email protected]>"
],
"version": "3.2.0",
"version": "3.3.0",
"repository": {
"type": "git",
"url": "https://github.com/chaijs/chai"
Expand Down

0 comments on commit df954cc

Please sign in to comment.