-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement 'to have no calls satisfying' assertion.
- Loading branch information
1 parent
280e701
commit b3d39f1
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
documentation/assertions/spy/to-have-no-calls-satisfying.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Passes if none of the calls to a spy [satisfy](http://unexpected.js.org/assertions/any/to-satisfy/) a given spec: | ||
|
||
```js | ||
var increment = sinon.spy(function increment(n) { | ||
return n + 1; | ||
}); | ||
increment(42); | ||
increment(46); | ||
expect(increment, 'to have no calls satisfying', { args: [ 43 ], returnValue: 44 }); | ||
``` | ||
|
||
In case of a failing expectation you get the following output: | ||
|
||
```js | ||
var quux = sinon.spy().named('quux'); | ||
quux(789); | ||
quux(123, 456); | ||
|
||
expect(quux, 'to have no calls satisfying', { args: [ 123, 456 ] }); | ||
``` | ||
|
||
```output | ||
expected quux to have no calls satisfying { args: [ 123, 456 ] } | ||
quux( 789 ); at theFunction (theFileName:xx:yy) | ||
quux( 123, 456 ); at theFunction (theFileName:xx:yy) // should be removed | ||
``` | ||
|
||
An array value will be interpreted as a shorthand for `{ args: ... }`: | ||
|
||
```js | ||
expect(quux, 'to have no calls satisfying', [ 123 ]); | ||
``` | ||
|
||
Likewise for an object with only numerical properties: | ||
|
||
```js | ||
expect(quux, 'to have a call satisfying', { 1: 789 }); | ||
``` | ||
|
||
Note that the individual parameters are matched with | ||
[`to satisfy`](http://unexpected.js.org/assertions/any/to-satisfy/) | ||
semantics, so the following fails despite the actual call | ||
also had a `bar` property in the object passed as the first | ||
parameter: | ||
|
||
```js | ||
var mySpy = sinon.spy().named('mySpy'); | ||
mySpy({foo: 123, bar: 456}); | ||
expect(mySpy, 'to have no calls satisfying', { args: [ { foo: 123 } ] }); | ||
``` | ||
|
||
```output | ||
expected mySpy to have no calls satisfying { args: [ { foo: 123 } ] } | ||
mySpy( { foo: 123, bar: 456 } ); at theFunction (theFileName:xx:yy) // should be removed | ||
``` | ||
|
||
If that's not what you want, consider using the `exhaustively` flag. Then | ||
the assertion passes because none of the calls matched exhaustively: | ||
|
||
```js | ||
expect(mySpy, 'to have no calls exhaustively satisfying', { args: [ { foo: 123 } ] }); | ||
``` | ||
|
||
You can also specify the expected call as a function that performs it: | ||
|
||
```js | ||
var foo = sinon.spy().named('foo'); | ||
foo(1); | ||
foo(2); | ||
|
||
expect(foo, 'to have no calls satisfying', function () { | ||
foo(1); | ||
}); | ||
``` | ||
|
||
```output | ||
expected foo to have no calls satisfying foo( 1 ); | ||
foo( 1 ); at theFunction (theFileName:xx:yy) // should be removed | ||
foo( 2 ); at theFunction (theFileName:xx:yy) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters