vendor/assets/javascripts/chai-changes.js in konacha-chai-matchers-0.1.3 vs vendor/assets/javascripts/chai-changes.js in konacha-chai-matchers-0.1.4
- old
+ new
@@ -1,8 +1,7 @@
-// Generated by CoffeeScript 1.3.3
+// Generated by CoffeeScript 1.6.3
(function() {
-
(function(chaiChanges) {
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
return module.exports = chaiChanges;
} else if (typeof define === "function" && define.amd) {
return define(function() {
@@ -10,11 +9,11 @@
});
} else {
return chai.use(chaiChanges);
}
})(function(chai, utils) {
- var byAtLeast, byAtMost, changeBy, changeByAssert, changeFrom, changeFromAssert, changeFromBeginAssert, changeTo, changeToAssert, changeToBeginAssert, flag, formatFunction, inspect, noChangeAssert;
+ var byAtLeast, byAtMost, changeBy, changeByAssert, changeFrom, changeFromAssert, changeFromBeginAssert, changeTo, changeToAssert, changeToBeginAssert, clone, flag, formatFunction, inspect, noChangeAssert;
inspect = utils.inspect;
flag = utils.flag;
chai.Assertion.addMethod('when', function(val, options) {
var action, definedActions, done, isPromise, newPromise, object, promiseCallback, result, _i, _j, _len, _len1,
_this = this;
@@ -36,20 +35,21 @@
done = options != null ? options.notify : void 0;
if (done == null) {
done = function() {};
}
promiseCallback = function() {
- var _j, _len1;
+ var error, _j, _len1;
try {
for (_j = 0, _len1 = definedActions.length; _j < _len1; _j++) {
action = definedActions[_j];
if (typeof action.after === "function") {
action.after(_this);
}
}
return done();
- } catch (error) {
+ } catch (_error) {
+ error = _error;
done(error);
throw error;
}
};
newPromise = result.then(promiseCallback, promiseCallback);
@@ -88,16 +88,31 @@
endValue = object();
actualDelta = endValue - startValue;
context.assert(this.expectedDelta === actualDelta, "expected `" + (formatFunction(object)) + "` to change by " + this.expectedDelta + ", but it changed by " + actualDelta, "expected `" + (formatFunction(object)) + "` not to change by " + this.expectedDelta + ", but it did");
return flag(context, 'negate', negate);
};
+ clone = function(obj) {
+ var key, result, value;
+ if (obj !== Object(obj)) {
+ return obj;
+ }
+ if (Array.isArray(obj)) {
+ return obj.slice();
+ }
+ result = {};
+ for (key in obj) {
+ value = obj[key];
+ result[key] = value;
+ }
+ return result;
+ };
changeToBeginAssert = function(context) {
var negate, object, result, startValue;
negate = flag(context, 'negate');
flag(context, 'negate', this.negate);
object = flag(context, 'whenObject');
startValue = object();
- flag(context, 'changeToStart', startValue);
+ flag(context, 'changeToStart', clone(startValue));
result = !utils.eql(startValue, this.expectedEndValue);
if (negate) {
result = !result;
}
context.assert(result, "expected `" + (formatFunction(object)) + "` to change to " + (utils.inspect(this.expectedEndValue)) + ", but it was already " + (utils.inspect(startValue)), "not supported");