diff --git a/README.md b/README.md index a2d531b..c7b991e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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) \ No newline at end of file diff --git a/package.json b/package.json index d660af4..b6674d6 100644 --- a/package.json +++ b/package.json @@ -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",