@@ -15,7 +15,7 @@ var used = []
1515 * Chai version
1616 */
1717
18- exports . version = '3.2 .0' ;
18+ exports . version = '3.3 .0' ;
1919
2020/*!
2121 * Assertion Error
@@ -503,7 +503,7 @@ module.exports = function (chai, _) {
503503 for ( var k in val ) subset [ k ] = obj [ k ] ;
504504 expected = _ . eql ( subset , val ) ;
505505 } else {
506- expected = obj && ~ obj . indexOf ( val ) ;
506+ expected = ( obj != undefined ) && ~ obj . indexOf ( val ) ;
507507 }
508508 this . assert (
509509 expected
@@ -681,17 +681,8 @@ module.exports = function (chai, _) {
681681 */
682682
683683 Assertion . addProperty ( 'empty' , function ( ) {
684- var obj = flag ( this , 'object' )
685- , expected = obj ;
686-
687- if ( Array . isArray ( obj ) || 'string' === typeof object ) {
688- expected = obj . length ;
689- } else if ( typeof obj === 'object' ) {
690- expected = Object . keys ( obj ) . length ;
691- }
692-
693684 this . assert (
694- ! expected
685+ Object . keys ( Object ( flag ( this , 'object' ) ) ) . length === 0
695686 , 'expected #{this} to be empty'
696687 , 'expected #{this} not to be empty'
697688 ) ;
@@ -1727,7 +1718,7 @@ module.exports = function (chai, _) {
17271718 , result
17281719 ) ;
17291720 }
1730-
1721+
17311722 Assertion . addMethod ( 'satisfy' , satisfy ) ;
17321723 Assertion . addMethod ( 'satisfies' , satisfy ) ;
17331724
@@ -1937,7 +1928,7 @@ module.exports = function (chai, _) {
19371928 /**
19381929 * ### .extensible
19391930 *
1940- * Asserts that the target is extensible (can have new properties added to
1931+ * Asserts that the target is extensible (can have new properties added to
19411932 * it).
19421933 *
19431934 * var nonExtensibleObject = Object.preventExtensions({});
@@ -1956,8 +1947,22 @@ module.exports = function (chai, _) {
19561947 Assertion . addProperty ( 'extensible' , function ( ) {
19571948 var obj = flag ( this , 'object' ) ;
19581949
1950+ // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
1951+ // In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
1952+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
1953+ // The following provides ES6 behavior when a TypeError is thrown under ES5.
1954+
1955+ var isExtensible ;
1956+
1957+ try {
1958+ isExtensible = Object . isExtensible ( obj ) ;
1959+ } catch ( err ) {
1960+ if ( err instanceof TypeError ) isExtensible = false ;
1961+ else throw err ;
1962+ }
1963+
19591964 this . assert (
1960- Object . isExtensible ( obj )
1965+ isExtensible
19611966 , 'expected #{this} to be extensible'
19621967 , 'expected #{this} to not be extensible'
19631968 ) ;
@@ -1983,8 +1988,22 @@ module.exports = function (chai, _) {
19831988 Assertion . addProperty ( 'sealed' , function ( ) {
19841989 var obj = flag ( this , 'object' ) ;
19851990
1991+ // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
1992+ // In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
1993+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
1994+ // The following provides ES6 behavior when a TypeError is thrown under ES5.
1995+
1996+ var isSealed ;
1997+
1998+ try {
1999+ isSealed = Object . isSealed ( obj ) ;
2000+ } catch ( err ) {
2001+ if ( err instanceof TypeError ) isSealed = true ;
2002+ else throw err ;
2003+ }
2004+
19862005 this . assert (
1987- Object . isSealed ( obj )
2006+ isSealed
19882007 , 'expected #{this} to be sealed'
19892008 , 'expected #{this} to not be sealed'
19902009 ) ;
@@ -2008,13 +2027,26 @@ module.exports = function (chai, _) {
20082027 Assertion . addProperty ( 'frozen' , function ( ) {
20092028 var obj = flag ( this , 'object' ) ;
20102029
2030+ // In ES5, if the argument to this method is not an object (a primitive), then it will cause a TypeError.
2031+ // In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
2032+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
2033+ // The following provides ES6 behavior when a TypeError is thrown under ES5.
2034+
2035+ var isFrozen ;
2036+
2037+ try {
2038+ isFrozen = Object . isFrozen ( obj ) ;
2039+ } catch ( err ) {
2040+ if ( err instanceof TypeError ) isFrozen = true ;
2041+ else throw err ;
2042+ }
2043+
20112044 this . assert (
2012- Object . isFrozen ( obj )
2045+ isFrozen
20132046 , 'expected #{this} to be frozen'
20142047 , 'expected #{this} to not be frozen'
20152048 ) ;
20162049 } ) ;
2017-
20182050} ;
20192051
20202052} , { } ] , 6 :[ function ( require , module , exports ) {
@@ -2245,16 +2277,16 @@ module.exports = function (chai, util) {
22452277 new Assertion ( act , msg ) . to . not . eql ( exp ) ;
22462278 } ;
22472279
2248- /**
2249- * ### .isTrue(value , [message])
2280+ /**
2281+ * ### .isAbove(valueToCheck, valueToBeAbove , [message])
22502282 *
2251- * Asserts that `value ` is true.
2283+ * Asserts `valueToCheck ` is strictly greater than (>) `valueToBeAbove`
22522284 *
2253- * var teaServed = true;
2254- * assert.isTrue(teaServed, 'the tea has been served');
2285+ * assert.isAbove(5, 2, '5 is strictly greater than 2');
22552286 *
2256- * @name isTrue
2257- * @param {Mixed } value
2287+ * @name isAbove
2288+ * @param {Mixed } valueToCheck
2289+ * @param {Mixed } valueToBeAbove
22582290 * @param {String } message
22592291 * @api public
22602292 */
@@ -2264,21 +2296,22 @@ module.exports = function (chai, util) {
22642296 } ;
22652297
22662298 /**
2267- * ### .isAbove (valueToCheck, valueToBeAbove , [message])
2299+ * ### .isAtLeast (valueToCheck, valueToBeAtLeast , [message])
22682300 *
2269- * Asserts `valueToCheck` is strictly greater than (> ) `valueToBeAbove `
2301+ * Asserts `valueToCheck` is greater than or equal to (>= ) `valueToBeAtLeast `
22702302 *
2271- * assert.isAbove(5, 2, '5 is strictly greater than 2');
2303+ * assert.isAtLeast(5, 2, '5 is greater or equal to 2');
2304+ * assert.isAtLeast(3, 3, '3 is greater or equal to 3');
22722305 *
2273- * @name isAbove
2306+ * @name isAtLeast
22742307 * @param {Mixed } valueToCheck
2275- * @param {Mixed } valueToBeAbove
2308+ * @param {Mixed } valueToBeAtLeast
22762309 * @param {String } message
22772310 * @api public
22782311 */
22792312
2280- assert . isBelow = function ( val , blw , msg ) {
2281- new Assertion ( val , msg ) . to . be . below ( blw ) ;
2313+ assert . isAtLeast = function ( val , atlst , msg ) {
2314+ new Assertion ( val , msg ) . to . be . least ( atlst ) ;
22822315 } ;
22832316
22842317 /**
@@ -2295,10 +2328,65 @@ module.exports = function (chai, util) {
22952328 * @api public
22962329 */
22972330
2331+ assert . isBelow = function ( val , blw , msg ) {
2332+ new Assertion ( val , msg ) . to . be . below ( blw ) ;
2333+ } ;
2334+
2335+ /**
2336+ * ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
2337+ *
2338+ * Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`
2339+ *
2340+ * assert.isAtMost(3, 6, '3 is less than or equal to 6');
2341+ * assert.isAtMost(4, 4, '4 is less than or equal to 4');
2342+ *
2343+ * @name isAtMost
2344+ * @param {Mixed } valueToCheck
2345+ * @param {Mixed } valueToBeAtMost
2346+ * @param {String } message
2347+ * @api public
2348+ */
2349+
2350+ assert . isAtMost = function ( val , atmst , msg ) {
2351+ new Assertion ( val , msg ) . to . be . most ( atmst ) ;
2352+ } ;
2353+
2354+ /**
2355+ * ### .isTrue(value, [message])
2356+ *
2357+ * Asserts that `value` is true.
2358+ *
2359+ * var teaServed = true;
2360+ * assert.isTrue(teaServed, 'the tea has been served');
2361+ *
2362+ * @name isTrue
2363+ * @param {Mixed } value
2364+ * @param {String } message
2365+ * @api public
2366+ */
2367+
22982368 assert . isTrue = function ( val , msg ) {
22992369 new Assertion ( val , msg ) . is [ 'true' ] ;
23002370 } ;
23012371
2372+ /**
2373+ * ### .isNotTrue(value, [message])
2374+ *
2375+ * Asserts that `value` is not true.
2376+ *
2377+ * var tea = 'tasty chai';
2378+ * assert.isNotTrue(tea, 'great, time for tea!');
2379+ *
2380+ * @name isNotTrue
2381+ * @param {Mixed } value
2382+ * @param {String } message
2383+ * @api public
2384+ */
2385+
2386+ assert . isNotTrue = function ( val , msg ) {
2387+ new Assertion ( val , msg ) . to . not . equal ( true ) ;
2388+ } ;
2389+
23022390 /**
23032391 * ### .isFalse(value, [message])
23042392 *
@@ -2317,6 +2405,24 @@ module.exports = function (chai, util) {
23172405 new Assertion ( val , msg ) . is [ 'false' ] ;
23182406 } ;
23192407
2408+ /**
2409+ * ### .isNotFalse(value, [message])
2410+ *
2411+ * Asserts that `value` is not false.
2412+ *
2413+ * var tea = 'tasty chai';
2414+ * assert.isNotFalse(tea, 'great, time for tea!');
2415+ *
2416+ * @name isNotFalse
2417+ * @param {Mixed } value
2418+ * @param {String } message
2419+ * @api public
2420+ */
2421+
2422+ assert . isNotFalse = function ( val , msg ) {
2423+ new Assertion ( val , msg ) . to . not . equal ( false ) ;
2424+ } ;
2425+
23202426 /**
23212427 * ### .isNull(value, [message])
23222428 *
@@ -3757,6 +3863,9 @@ module.exports = function (ctx, name, method) {
37573863 * MIT Licensed
37583864 */
37593865
3866+ var config = require ( '../config' ) ;
3867+ var flag = require ( './flag' ) ;
3868+
37603869/**
37613870 * ### addProperty (ctx, name, getter)
37623871 *
@@ -3784,15 +3893,19 @@ module.exports = function (ctx, name, method) {
37843893
37853894module . exports = function ( ctx , name , getter ) {
37863895 Object . defineProperty ( ctx , name ,
3787- { get : function ( ) {
3896+ { get : function addProperty ( ) {
3897+ var old_ssfi = flag ( this , 'ssfi' ) ;
3898+ if ( old_ssfi && config . includeStack === false )
3899+ flag ( this , 'ssfi' , addProperty ) ;
3900+
37883901 var result = getter . call ( this ) ;
37893902 return result === undefined ? this : result ;
37903903 }
37913904 , configurable : true
37923905 } ) ;
37933906} ;
37943907
3795- } , { } ] , 12 :[ function ( require , module , exports ) {
3908+ } , { "../config" : 4 , "./flag" : 12 } ] , 12 :[ function ( require , module , exports ) {
37963909/*!
37973910 * Chai - flag utility
37983911 * Copyright(c) 2012-2014 Jake Luer <[email protected] >
0 commit comments