vendor/assets/javascripts/chai.js in konacha-3.6.0 vs vendor/assets/javascripts/chai.js in konacha-3.7.0

- old
+ new

@@ -13,11 +13,11 @@ /*! * Chai version */ -exports.version = '3.0.0'; +exports.version = '3.3.0'; /*! * Assertion Error */ @@ -501,11 +501,11 @@ } var subset = {}; 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 , 'expected #{this} to include ' + _.inspect(val) , 'expected #{this} to not include ' + _.inspect(val)); @@ -619,10 +619,29 @@ , 'expected #{this} not to be undefined' ); }); /** + * ### .NaN + * Asserts that the target is `NaN`. + * + * expect('foo').to.be.NaN; + * expect(4).not.to.be.NaN; + * + * @name NaN + * @api public + */ + + Assertion.addProperty('NaN', function () { + this.assert( + isNaN(flag(this, 'object')) + , 'expected #{this} to be NaN' + , 'expected #{this} not to be NaN' + ); + }); + + /** * ### .exist * * Asserts that the target is neither `null` nor `undefined`. * * var foo = 'hi' @@ -660,21 +679,12 @@ * @name empty * @api public */ 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' ); }); @@ -1636,16 +1646,17 @@ * * Klass.baz = function(){}; * expect(Klass).itself.to.respondTo('baz'); * * @name respondTo + * @alias respondsTo * @param {String} method * @param {String} message _optional_ * @api public */ - Assertion.addMethod('respondTo', function (method, msg) { + function respondTo (method, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object') , itself = flag(this, 'itself') , context = ('function' === _.type(obj) && !itself) ? obj.prototype[method] @@ -1654,12 +1665,15 @@ this.assert( 'function' === typeof context , 'expected #{this} to respond to ' + _.inspect(method) , 'expected #{this} to not respond to ' + _.inspect(method) ); - }); + } + Assertion.addMethod('respondTo', respondTo); + Assertion.addMethod('respondsTo', respondTo); + /** * ### .itself * * Sets the `itself` flag, later used by the `respondTo` assertion. * @@ -1684,28 +1698,32 @@ * Asserts that the target passes a given truth test. * * expect(1).to.satisfy(function(num) { return num > 0; }); * * @name satisfy + * @alias satisfies * @param {Function} matcher * @param {String} message _optional_ * @api public */ - Assertion.addMethod('satisfy', function (matcher, msg) { + function satisfy (matcher, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); var result = matcher(obj); this.assert( result , 'expected #{this} to satisfy ' + _.objDisplay(matcher) , 'expected #{this} to not satisfy' + _.objDisplay(matcher) , this.negate ? false : true , result ); - }); + } + Assertion.addMethod('satisfy', satisfy); + Assertion.addMethod('satisfies', satisfy); + /** * ### .closeTo(expected, delta) * * Asserts that the target is equal `expected`, to within a +/- `delta` range. * @@ -1905,10 +1923,132 @@ } Assertion.addChainableMethod('decrease', assertDecreases); Assertion.addChainableMethod('decreases', assertDecreases); + /** + * ### .extensible + * + * Asserts that the target is extensible (can have new properties added to + * it). + * + * var nonExtensibleObject = Object.preventExtensions({}); + * var sealedObject = Object.seal({}); + * var frozenObject = Object.freeze({}); + * + * expect({}).to.be.extensible; + * expect(nonExtensibleObject).to.not.be.extensible; + * expect(sealedObject).to.not.be.extensible; + * expect(frozenObject).to.not.be.extensible; + * + * @name extensible + * @api public + */ + + 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( + isExtensible + , 'expected #{this} to be extensible' + , 'expected #{this} to not be extensible' + ); + }); + + /** + * ### .sealed + * + * Asserts that the target is sealed (cannot have new properties added to it + * and its existing properties cannot be removed). + * + * var sealedObject = Object.seal({}); + * var frozenObject = Object.freeze({}); + * + * expect(sealedObject).to.be.sealed; + * expect(frozenObject).to.be.sealed; + * expect({}).to.not.be.sealed; + * + * @name sealed + * @api public + */ + + 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( + isSealed + , 'expected #{this} to be sealed' + , 'expected #{this} to not be sealed' + ); + }); + + /** + * ### .frozen + * + * Asserts that the target is frozen (cannot have new properties added to it + * and its existing properties cannot be modified). + * + * var frozenObject = Object.freeze({}); + * + * expect(frozenObject).to.be.frozen; + * expect({}).to.not.be.frozen; + * + * @name frozen + * @api public + */ + + 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( + isFrozen + , 'expected #{this} to be frozen' + , 'expected #{this} to not be frozen' + ); + }); }; },{}],6:[function(require,module,exports){ /*! * chai @@ -1974,42 +2114,44 @@ , operator: operator }, assert.fail); }; /** - * ### .ok(object, [message]) + * ### .isOk(object, [message]) * * Asserts that `object` is truthy. * - * assert.ok('everything', 'everything is ok'); - * assert.ok(false, 'this will fail'); + * assert.isOk('everything', 'everything is ok'); + * assert.isOk(false, 'this will fail'); * - * @name ok + * @name isOk + * @alias ok * @param {Mixed} object to test * @param {String} message * @api public */ - assert.ok = function (val, msg) { + assert.isOk = function (val, msg) { new Assertion(val, msg).is.ok; }; /** - * ### .notOk(object, [message]) + * ### .isNotOk(object, [message]) * * Asserts that `object` is falsy. * - * assert.notOk('everything', 'this will fail'); - * assert.notOk(false, 'this will pass'); + * assert.isNotOk('everything', 'this will fail'); + * assert.isNotOk(false, 'this will pass'); * - * @name notOk + * @name isNotOk + * @alias notOk * @param {Mixed} object to test * @param {String} message * @api public */ - assert.notOk = function (val, msg) { + assert.isNotOk = function (val, msg) { new Assertion(val, msg).is.not.ok; }; /** * ### .equal(actual, expected, [message]) @@ -2133,44 +2275,45 @@ assert.notDeepEqual = function (act, exp, msg) { 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 */ assert.isAbove = function (val, abv, msg) { new Assertion(val, msg).to.be.above(abv); }; /** - * ### .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); }; /** * ### .isBelow(valueToCheck, valueToBeBelow, [message]) * @@ -2183,15 +2326,70 @@ * @param {Mixed} valueToBeBelow * @param {String} message * @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]) * * Asserts that `value` is false. * * var teaServed = false; @@ -2206,10 +2404,28 @@ assert.isFalse = function (val, msg) { 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]) * * Asserts that `value` is null. * * assert.isNull(err, 'there was no error'); @@ -2241,10 +2457,41 @@ assert.isNotNull = function (val, msg) { new Assertion(val, msg).to.not.equal(null); }; /** + * ### .isNaN + * Asserts that value is NaN + * + * assert.isNaN('foo', 'foo is NaN'); + * + * @name isNaN + * @param {Mixed} value + * @param {String} message + * @api public + */ + + assert.isNaN = function (val, msg) { + new Assertion(val, msg).to.be.NaN; + }; + + /** + * ### .isNotNaN + * Asserts that value is not NaN + * + * assert.isNotNaN(4, '4 is not NaN'); + * + * @name isNotNaN + * @param {Mixed} value + * @param {String} message + * @api public + */ + assert.isNotNaN = function (val, msg) { + new Assertion(val, msg).not.to.be.NaN; + }; + + /** * ### .isUndefined(value, [message]) * * Asserts that `value` is `undefined`. * * var tea; @@ -2843,15 +3090,15 @@ * * Asserts that `function` will throw an error that is an instance of * `constructor`, or alternately that it will throw an error with message * matching `regexp`. * - * assert.throw(fn, 'function throws a reference error'); - * assert.throw(fn, /function throws a reference error/); - * assert.throw(fn, ReferenceError); - * assert.throw(fn, ReferenceError, 'function throws a reference error'); - * assert.throw(fn, ReferenceError, /function throws a reference error/); + * assert.throws(fn, 'function throws a reference error'); + * assert.throws(fn, /function throws a reference error/); + * assert.throws(fn, ReferenceError); + * assert.throws(fn, ReferenceError, 'function throws a reference error'); + * assert.throws(fn, ReferenceError, /function throws a reference error/); * * @name throws * @alias throw * @alias Throw * @param {Function} function @@ -2860,17 +3107,17 @@ * @param {String} message * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types * @api public */ - assert.Throw = function (fn, errt, errs, msg) { + assert.throws = function (fn, errt, errs, msg) { if ('string' === typeof errt || errt instanceof RegExp) { errs = errt; errt = null; } - var assertErr = new Assertion(fn, msg).to.Throw(errt, errs); + var assertErr = new Assertion(fn, msg).to.throw(errt, errs); return flag(assertErr, 'object'); }; /** * ### .doesNotThrow(function, [constructor/regexp], [message]) @@ -3156,11 +3403,11 @@ /*! * ### .ifError(object) * * Asserts if value is not a false value, and throws if it is a true value. - * This is added to allow for chai to be a drop-in replacement for Node's + * This is added to allow for chai to be a drop-in replacement for Node's * assert class. * * var err = new Error('I am a custom error'); * assert.ifError(err); // Rethrows err! * @@ -3173,20 +3420,149 @@ if (val) { throw(val); } }; + /** + * ### .isExtensible(object) + * + * Asserts that `object` is extensible (can have new properties added to it). + * + * assert.isExtensible({}); + * + * @name isExtensible + * @alias extensible + * @param {Object} object + * @param {String} message _optional_ + * @api public + */ + + assert.isExtensible = function (obj, msg) { + new Assertion(obj, msg).to.be.extensible; + }; + + /** + * ### .isNotExtensible(object) + * + * Asserts that `object` is _not_ extensible. + * + * var nonExtensibleObject = Object.preventExtensions({}); + * var sealedObject = Object.seal({}); + * var frozenObject = Object.freese({}); + * + * assert.isNotExtensible(nonExtensibleObject); + * assert.isNotExtensible(sealedObject); + * assert.isNotExtensible(frozenObject); + * + * @name isNotExtensible + * @alias notExtensible + * @param {Object} object + * @param {String} message _optional_ + * @api public + */ + + assert.isNotExtensible = function (obj, msg) { + new Assertion(obj, msg).to.not.be.extensible; + }; + + /** + * ### .isSealed(object) + * + * Asserts that `object` is sealed (cannot have new properties added to it + * and its existing properties cannot be removed). + * + * var sealedObject = Object.seal({}); + * var frozenObject = Object.seal({}); + * + * assert.isSealed(sealedObject); + * assert.isSealed(frozenObject); + * + * @name isSealed + * @alias sealed + * @param {Object} object + * @param {String} message _optional_ + * @api public + */ + + assert.isSealed = function (obj, msg) { + new Assertion(obj, msg).to.be.sealed; + }; + + /** + * ### .isNotSealed(object) + * + * Asserts that `object` is _not_ sealed. + * + * assert.isNotSealed({}); + * + * @name isNotSealed + * @alias notSealed + * @param {Object} object + * @param {String} message _optional_ + * @api public + */ + + assert.isNotSealed = function (obj, msg) { + new Assertion(obj, msg).to.not.be.sealed; + }; + + /** + * ### .isFrozen(object) + * + * Asserts that `object` is frozen (cannot have new properties added to it + * and its existing properties cannot be modified). + * + * var frozenObject = Object.freeze({}); + * assert.frozen(frozenObject); + * + * @name isFrozen + * @alias frozen + * @param {Object} object + * @param {String} message _optional_ + * @api public + */ + + assert.isFrozen = function (obj, msg) { + new Assertion(obj, msg).to.be.frozen; + }; + + /** + * ### .isNotFrozen(object) + * + * Asserts that `object` is _not_ frozen. + * + * assert.isNotFrozen({}); + * + * @name isNotFrozen + * @alias notFrozen + * @param {Object} object + * @param {String} message _optional_ + * @api public + */ + + assert.isNotFrozen = function (obj, msg) { + new Assertion(obj, msg).to.not.be.frozen; + }; + /*! * Aliases. */ (function alias(name, as){ assert[as] = assert[name]; return alias; }) - ('Throw', 'throw') - ('Throw', 'throws'); + ('isOk', 'ok') + ('isNotOk', 'notOk') + ('throws', 'throw') + ('throws', 'Throw') + ('isExtensible', 'extensible') + ('isNotExtensible', 'notExtensible') + ('isSealed', 'sealed') + ('isNotSealed', 'notSealed') + ('isFrozen', 'frozen') + ('isNotFrozen', 'notFrozen'); }; },{}],7:[function(require,module,exports){ /*! * chai @@ -3485,10 +3861,13 @@ * Chai - addProperty utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ +var config = require('../config'); +var flag = require('./flag'); + /** * ### addProperty (ctx, name, getter) * * Adds a property to the prototype of an object. * @@ -3512,19 +3891,23 @@ * @api public */ 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 <jake@alogicalparadox.com> * MIT Licensed */ @@ -3851,18 +4234,18 @@ * @name getProperties * @api public */ module.exports = function getProperties(object) { - var result = Object.getOwnPropertyNames(subject); + var result = Object.getOwnPropertyNames(object); function addProperty(property) { if (result.indexOf(property) === -1) { result.push(property); } } - var proto = Object.getPrototypeOf(subject); + var proto = Object.getPrototypeOf(object); while (proto !== null) { Object.getOwnPropertyNames(proto).forEach(addProperty); proto = Object.getPrototypeOf(proto); } \ No newline at end of file