Skip to content

Commit

Permalink
Version bumped to 2.3.0, readme updated with thenResolve / thenReject…
Browse files Browse the repository at this point in the history
… methods
  • Loading branch information
NagRock committed Feb 27, 2018
1 parent 7c6eb6a commit ba5997f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Mocking library for TypeScript inspired by http://mockito.org/
* `thenReturn` - return value
* `thenThrow` - throw an error
* `thenCall` - call custom method
* `thenResolve` - resolve promise
* `thenReject` - rejects promise
* Checking if methods were called with given arguments (`verify`)
* `anything`, `notNull`, `anyString`, `anyOfClass` etc. - for more flexible comparision
* `once`, `twice`, `times`, `atLeast` etc. - allows call count verification
Expand Down Expand Up @@ -166,6 +168,17 @@ when(mockedFoo.sumTwoNumbers(anyNumber(), anyNumber())).thenCall((arg1:number, a
console.log(foo.sumTwoNumbers(5, 10));
```
### Resolving / rejecting promises
You can also stub method to resolve / reject promise
``` typescript
let mockedFoo:Foo = mock(Foo);

when(mockedFoo.fetchData("a")).thenResolve({id: "a", value: "Hello world"});
when(mockedFoo.fetchData("b")).thenReject(new Error("b does not exist"));
```
### Resetting mock calls
You can reset just mock call counter
Expand Down Expand Up @@ -348,3 +361,4 @@ console.log(capture(spiedFoo.bar).last()); // [42]
* Andrey Ermakov (https://github.com/dreef3)
* Markus Ende (https://github.com/Markus-Ende)
* Thomas Hilzendegen (https://github.com/thomashilzendegen)
* Johan Blumenberg (https://github.com/johanblumenberg)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-mockito",
"version": "2.2.10",
"version": "2.3.0",
"description": "Mocking library for TypeScript",
"main": "lib/ts-mockito.js",
"typings": "lib/ts-mockito",
Expand Down

0 comments on commit ba5997f

Please sign in to comment.