vendor/assets/javascripts/chai-changes.js in konacha-chai-matchers-0.0.3 vs vendor/assets/javascripts/chai-changes.js in konacha-chai-matchers-0.0.4

- old
+ new

@@ -20,82 +20,88 @@ # Changes Matchers # */ chai.Assertion.addMethod('when', function(val, options) { - var action, definedActions, done, result, _i, _j, _len, _len1, _results, + var action, definedActions, done, object, promiseCallback, result, _i, _j, _len, _len1, _this = this; if (options == null) { options = {}; } definedActions = flag(this, 'whenActions') || []; + object = flag(this, 'object'); + flag(this, 'whenObject', object); for (_i = 0, _len = definedActions.length; _i < _len; _i++) { action = definedActions[_i]; if (typeof action.before === "function") { action.before(this); } } result = val(); - if (result.then != null) { + flag(this, 'object', result); + if ((result != null ? result.then : void 0) != null) { done = options != null ? options.notify : void 0; if (done == null) { done = function() {}; } - return result.then(function() { + promiseCallback = function() { var _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) { - return done(new Error(error)); + done(new Error(error)); + throw new Error(error); } - }); + }; + result.then(promiseCallback, promiseCallback); } else { - _results = []; for (_j = 0, _len1 = definedActions.length; _j < _len1; _j++) { action = definedActions[_j]; - _results.push(typeof action.after === "function" ? action.after(this) : void 0); + if (typeof action.after === "function") { + action.after(this); + } } - return _results; } + return this; }); noChangeAssert = function(context) { var endValue, negate, object, relevant, result, startValue; relevant = flag(context, 'no-change'); if (!relevant) { return; } negate = flag(context, 'negate'); flag(context, 'negate', this.negate); - object = flag(context, 'object'); + object = flag(context, 'whenObject'); startValue = flag(context, 'changeStart'); endValue = object(); result = !utils.eql(endValue, startValue); context.assert(result, "expected `" + (formatFunction(object)) + "` to change, but it stayed " + (utils.inspect(startValue)), "expected `" + (formatFunction(object)) + "` not to change, but it changed from " + (utils.inspect(startValue)) + " to " + (utils.inspect(endValue))); return flag(context, 'negate', negate); }; changeByAssert = function(context) { var actualDelta, endValue, negate, object, startValue; negate = flag(context, 'negate'); flag(context, 'negate', this.negate); - object = flag(context, 'object'); + object = flag(context, 'whenObject'); startValue = flag(context, 'changeStart'); 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); }; changeToBeginAssert = function(context) { var negate, object, result, startValue; negate = flag(context, 'negate'); flag(context, 'negate', this.negate); - object = flag(context, 'object'); + object = flag(context, 'whenObject'); startValue = object(); result = !utils.eql(startValue, this.expectedEndValue); if (negate) { result = !result; } @@ -104,31 +110,31 @@ }; changeToAssert = function(context) { var endValue, negate, object, result; negate = flag(context, 'negate'); flag(context, 'negate', this.negate); - object = flag(context, 'object'); + object = flag(context, 'whenObject'); endValue = object(); result = utils.eql(endValue, this.expectedEndValue); context.assert(result, "expected `" + (formatFunction(object)) + "` to change to " + (utils.inspect(this.expectedEndValue)) + ", but it changed to " + (utils.inspect(endValue)), "expected `" + (formatFunction(object)) + "` not to change to " + (utils.inspect(this.expectedEndValue)) + ", but it did"); return flag(context, 'negate', negate); }; changeFromBeginAssert = function(context) { var negate, object, result, startValue; negate = flag(context, 'negate'); flag(context, 'negate', this.negate); - object = flag(context, 'object'); + object = flag(context, 'whenObject'); startValue = object(); result = utils.eql(startValue, this.expectedStartValue); context.assert(result, "expected the change of `" + (formatFunction(object)) + "` to start from " + (utils.inspect(this.expectedStartValue)) + ", but it started from " + (utils.inspect(startValue)), "expected the change of `" + (formatFunction(object)) + "` not to start from " + (utils.inspect(this.expectedStartValue)) + ", but it did"); return flag(context, 'negate', negate); }; changeFromAssert = function(context) { var endValue, negate, object, result, startValue; negate = flag(context, 'negate'); flag(context, 'negate', this.negate); - object = flag(context, 'object'); + object = flag(context, 'whenObject'); startValue = flag(context, 'changeStart'); endValue = object(); result = !utils.eql(startValue, endValue); if (negate) { result = !result; @@ -142,10 +148,10 @@ definedActions = flag(this, 'whenActions') || []; definedActions.push({ negate: flag(this, 'negate'), before: function(context) { var startValue; - startValue = flag(context, 'object')(); + startValue = flag(context, 'whenObject')(); return flag(context, 'changeStart', startValue); }, after: noChangeAssert }); return flag(this, 'whenActions', definedActions);