vendor/assets/javascripts/chai.js in konacha-1.2.2 vs vendor/assets/javascripts/chai.js in konacha-1.2.3
- old
+ new
@@ -303,15 +303,15 @@
* @alias contain
* @param {Object|String|Number} obj
* @api public
*/
-function includeChainingBehavior() {
+function includeChainingBehavior () {
flag(this, 'contains', true);
}
-function include(val) {
+function include (val) {
var obj = flag(this, 'object')
this.assert(
~obj.indexOf(val)
, 'expected #{this} to include ' + util.inspect(val)
, 'expected #{this} to not include ' + util.inspect(val));
@@ -525,28 +525,26 @@
* function test () {
* expect(arguments).to.be.arguments;
* }
*
* @name arguments
+ * @alias Arguments
* @api public
*/
-Object.defineProperty(Assertion.prototype, 'arguments',
- { get: function () {
- var obj = flag(this, 'object');
- this.assert(
- '[object Arguments]' == Object.prototype.toString.call(obj)
- , 'expected #{this} to be arguments'
- , 'expected #{this} to not be arguments'
- , '[object Arguments]'
- , Object.prototype.toString.call(obj)
- );
+function checkArguments () {
+ var obj = flag(this, 'object')
+ , type = Object.prototype.toString.call(obj);
+ this.assert(
+ '[object Arguments]' === type
+ , 'expected #{this} to be arguments but got ' + type
+ , 'expected #{this} to not be arguments'
+ );
+}
- return this;
- }
- , configurable: true
-});
+Assertion.addProperty('arguments', checkArguments);
+Assertion.addProperty('Arguments', checkArguments);
/**
* ### .equal(value)
*
* Asserts that the target is strictly equal (`===`) to `value`.
@@ -1040,21 +1038,29 @@
/**
* ### .respondTo(method)
*
* Asserts that the object or class target will respond to a method.
*
+ * Klass.prototype.bar = function(){};
* expect(Klass).to.respondTo('bar');
* expect(obj).to.respondTo('bar');
*
+ * To check if a constructor will respond to a static function,
+ * set the `itself` flag.
+ *
+ * Klass.baz = function(){};
+ * expect(Klass).itself.to.respondTo('baz');
+ *
* @name respondTo
* @param {String} method
* @api public
*/
Assertion.prototype.respondTo = function (method) {
var obj = flag(this, 'object')
- , context = ('function' === typeof obj)
+ , itself = flag(this, 'itself')
+ , context = ('function' === typeof obj && !itself)
? obj.prototype[method]
: obj[method];
this.assert(
'function' === typeof context
@@ -1066,10 +1072,33 @@
return this;
};
/**
+ * ### .itself
+ *
+ * Sets the `itself` flag, later used by the `respondTo` assertion.
+ *
+ * function Foo() {}
+ * Foo.bar = function() {}
+ * Foo.prototype.baz = function() {}
+ *
+ * expect(Foo).itself.to.respondTo('bar');
+ * expect(Foo).itself.not.to.respondTo('baz');
+ *
+ * @name itself
+ * @api public
+ */
+Object.defineProperty(Assertion.prototype, 'itself',
+ { get: function () {
+ flag(this, 'itself', true);
+ return this;
+ }
+ , configurable: true
+});
+
+/**
* ### .satisfy(method)
*
* Asserts that the target passes a given truth test.
*
* expect(1).to.satisfy(function(num) { return num > 0; });
@@ -1181,11 +1210,11 @@
/*!
* Chai version
*/
-exports.version = '1.0.3';
+exports.version = '1.0.4';
/*!
* Primary `Assertion` prototype
*/
@@ -2334,13 +2363,12 @@
* @name addChainableMethod
* @api public
*/
module.exports = function (ctx, name, method, chainingBehavior) {
- if (typeof chainingBehavior !== 'function') {
+ if (typeof chainingBehavior !== 'function')
chainingBehavior = function () { };
- }
Object.defineProperty(ctx, name,
{ get: function () {
chainingBehavior.call(this);
@@ -2350,24 +2378,19 @@
};
// Re-enumerate every time to better accomodate plugins.
var asserterNames = Object.getOwnPropertyNames(ctx);
asserterNames.forEach(function (asserterName) {
- var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
-
- // Avoid trying to overwrite things that we can't, like `length`
- // and `arguments`.
- var functionProtoPD = Object.getOwnPropertyDescriptor(Function.prototype, asserterName);
- if (functionProtoPD && !functionProtoPD.configurable) {
- return;
- }
-
+ var pd = Object.getOwnPropertyDescriptor(ctx, asserterName)
+ , functionProtoPD = Object.getOwnPropertyDescriptor(Function.prototype, asserterName);
+ // Avoid trying to overwrite things that we can't, like `length` and `arguments`.
+ if (functionProtoPD && !functionProtoPD.configurable) return;
+ if (asserterName === 'arguments') return; // @see chaijs/chai/issues/69
Object.defineProperty(assert, asserterName, pd);
});
transferFlags(this, assert);
-
return assert;
}
, configurable: true
});
};
@@ -2998,11 +3021,11 @@
base = ' ' + Date.prototype.toUTCString.call(value);
}
// Make error with message first say the error
if (isError(value)) {
- base = ' ' + formatError(value);
+ return formatError(value);
}
if (keys.length === 0 && (!array || value.length == 0)) {
return braces[0] + base + braces[1];
}
@@ -3179,9 +3202,10 @@
}
function objectToString(o) {
return Object.prototype.toString.call(o);
}
+
}); // module: utils/inspect.js
require.register("utils/overwriteMethod.js", function(module, exports, require){
/*!
* Chai - overwriteMethod utility
\ No newline at end of file