Skip to content

Commit

Permalink
fixed expect('').to.contain('') so it passes
Browse files Browse the repository at this point in the history
  • Loading branch information
dereke committed Sep 1, 2015
1 parent a42ac43 commit a86a6e7
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 32 deletions.
168 changes: 137 additions & 31 deletions chai.js
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,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
1 change: 1 addition & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ describe('assert', function () {

it('include', function() {
assert.include('foobar', 'bar');
assert.include('', '');
assert.include([ 1, 2, 3], 3);
assert.include({a:1, b:2}, {b:2});

Expand Down

0 comments on commit a86a6e7

Please sign in to comment.