chai-changes
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.3.3 | ||
// Generated by CoffeeScript 1.4.0 | ||
(function() { | ||
@@ -15,11 +15,5 @@ | ||
})(function(chai, utils) { | ||
var changeBy, changeByAssert, changeFrom, changeFromAssert, changeFromBeginAssert, changeTo, changeToAssert, changeToBeginAssert, flag, formatFunction, inspect, noChangeAssert; | ||
var byAtLeast, byAtMost, changeBy, changeByAssert, changeFrom, changeFromAssert, changeFromBeginAssert, changeTo, changeToAssert, changeToBeginAssert, flag, formatFunction, inspect, noChangeAssert; | ||
inspect = utils.inspect; | ||
flag = utils.flag; | ||
/* | ||
# | ||
# Changes Matchers | ||
# | ||
*/ | ||
chai.Assertion.addMethod('when', function(val, options) { | ||
@@ -58,4 +52,4 @@ var action, definedActions, done, isPromise, newPromise, object, promiseCallback, result, _i, _j, _len, _len1, | ||
} catch (error) { | ||
done(new Error(error)); | ||
throw new Error(error); | ||
done(error); | ||
throw error; | ||
} | ||
@@ -72,5 +66,3 @@ }; | ||
} | ||
flag(this, 'object', result); | ||
} | ||
flag(this, 'negate', false); | ||
return this; | ||
@@ -166,2 +158,108 @@ }); | ||
}); | ||
chai.Assertion.addProperty('increase', function() { | ||
var definedActions; | ||
definedActions = flag(this, 'whenActions') || []; | ||
definedActions.push({ | ||
negate: flag(this, 'negate'), | ||
before: function(context) { | ||
var startValue; | ||
startValue = flag(context, 'whenObject')(); | ||
return flag(context, 'increaseStart', startValue); | ||
}, | ||
after: function(context) { | ||
var endValue, negate, object, startValue; | ||
object = flag(context, 'whenObject'); | ||
endValue = object(); | ||
startValue = flag(context, 'increaseStart'); | ||
negate = flag(context, 'negate'); | ||
flag(context, 'negate', this.negate); | ||
if (!negate) { | ||
context.assert(startValue !== endValue, "expected `" + (formatFunction(object)) + "` to increase, but it did not change", "not supported"); | ||
} | ||
context.assert(startValue < endValue, "expected `" + (formatFunction(object)) + "` to increase, but it decreased by " + (startValue - endValue), "expected `" + (formatFunction(object)) + "` not to increase, but it increased by " + (endValue - startValue)); | ||
return flag(context, 'negate', negate); | ||
} | ||
}); | ||
return flag(this, 'whenActions', definedActions); | ||
}); | ||
chai.Assertion.addProperty('decrease', function() { | ||
var definedActions; | ||
definedActions = flag(this, 'whenActions') || []; | ||
definedActions.push({ | ||
negate: flag(this, 'negate'), | ||
before: function(context) { | ||
var startValue; | ||
startValue = flag(context, 'whenObject')(); | ||
return flag(context, 'decreaseStart', startValue); | ||
}, | ||
after: function(context) { | ||
var endValue, negate, object, startValue; | ||
object = flag(context, 'whenObject'); | ||
endValue = object(); | ||
startValue = flag(context, 'decreaseStart'); | ||
negate = flag(context, 'negate'); | ||
flag(context, 'negate', this.negate); | ||
if (!negate) { | ||
context.assert(startValue !== endValue, "expected `" + (formatFunction(object)) + "` to decrease, but it did not change", "not supported"); | ||
} | ||
context.assert(startValue > endValue, "expected `" + (formatFunction(object)) + "` to decrease, but it increased by " + (endValue - startValue), "expected `" + (formatFunction(object)) + "` not to decrease, but it decreased by " + (startValue - endValue)); | ||
return flag(context, 'negate', negate); | ||
} | ||
}); | ||
return flag(this, 'whenActions', definedActions); | ||
}); | ||
byAtLeast = function(amount) { | ||
var definedActions; | ||
definedActions = flag(this, 'whenActions') || []; | ||
definedActions.push({ | ||
negate: flag(this, 'negate'), | ||
before: function(context) { | ||
var startValue; | ||
startValue = flag(context, 'whenObject')(); | ||
return flag(context, 'atLeastStart', startValue); | ||
}, | ||
after: function(context) { | ||
var difference, endValue, negate, object, startValue; | ||
object = flag(context, 'whenObject'); | ||
endValue = object(); | ||
startValue = flag(context, 'atLeastStart'); | ||
negate = flag(context, 'negate'); | ||
flag(context, 'negate', this.negate); | ||
difference = Math.abs(endValue - startValue); | ||
context.assert(difference >= amount, "expected `" + (formatFunction(object)) + "` to change by at least " + amount + ", but changed by " + difference, "not supported"); | ||
return flag(context, 'negate', negate); | ||
} | ||
}); | ||
return flag(this, 'whenActions', definedActions); | ||
}; | ||
chai.Assertion.addChainableMethod('atLeast', byAtLeast, function() { | ||
return this; | ||
}); | ||
byAtMost = function(amount) { | ||
var definedActions; | ||
definedActions = flag(this, 'whenActions') || []; | ||
definedActions.push({ | ||
negate: flag(this, 'negate'), | ||
before: function(context) { | ||
var startValue; | ||
startValue = flag(context, 'whenObject')(); | ||
return flag(context, 'atMostStart', startValue); | ||
}, | ||
after: function(context) { | ||
var difference, endValue, negate, object, startValue; | ||
object = flag(context, 'whenObject'); | ||
endValue = object(); | ||
startValue = flag(context, 'atMostStart'); | ||
negate = flag(context, 'negate'); | ||
flag(context, 'negate', this.negate); | ||
difference = Math.abs(endValue - startValue); | ||
context.assert(difference <= amount, "expected `" + (formatFunction(object)) + "` to change by at most " + amount + ", but changed by " + difference, "not supported"); | ||
return flag(context, 'negate', negate); | ||
} | ||
}); | ||
return flag(this, 'whenActions', definedActions); | ||
}; | ||
chai.Assertion.addChainableMethod('atMost', byAtMost, function() { | ||
return this; | ||
}); | ||
formatFunction = function(func) { | ||
@@ -168,0 +266,0 @@ return func.toString().replace(/^\s*function \(\) {\s*/, '').replace(/\s+}$/, '').replace(/\s*return\s*/, ''); |
@@ -6,3 +6,3 @@ { | ||
"keywords": [ "test", "assertion", "assert", "testing", "changes", "promises" ], | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -113,2 +113,44 @@ chai-changes | ||
### `increase` | ||
Assert if the value increases when an action is performed | ||
```coffeescript | ||
result = 0 | ||
expect(-> result).to.increase.when -> result += 1 | ||
expect(-> result).not.to.increase.when -> result | ||
expect(-> result).not.to.increase.when -> result -= 1 | ||
``` | ||
### `decrease` | ||
Assert if the value decreases when an action is performed | ||
```coffeescript | ||
result = 0 | ||
expect(-> result).to.decrease.when -> result -= 1 | ||
expect(-> result).not.to.decrease.when -> result | ||
expect(-> result).not.to.decrease.when -> result += 1 | ||
``` | ||
### `atLeast(amount)` | ||
Assert if the value has a minimal change of 'amount' | ||
```coffeescript | ||
result = 0 | ||
expect(-> result).to.change.by.atLeast(4).when -> result += 5 | ||
expect(-> result).to.change.by.atLeast(4).when -> result -= 10 | ||
``` | ||
### `atMost(amount)` | ||
Assert if the value has a maximum change of 'amount' | ||
```coffeescript | ||
result = 0 | ||
expect(-> result).to.change.by.atMost(7).when -> result += 5 | ||
expect(-> result).to.change.by.atMost(14).when -> result -= 10 | ||
``` | ||
## Installation and Setup | ||
@@ -115,0 +157,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40867
318
204