Skip to content

Commit

Permalink
chore: docs change
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 17, 2024
1 parent c258231 commit 00b00ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# tinyspy

> minimal fork of nanospy, with more features 🕵🏻‍♂️
Expand Down Expand Up @@ -60,7 +59,7 @@ console.log(spied.calls) // []
console.log(spied.returns) // []
```

If you have async implementation, you need to `await` the method to get awaited results (if you don't, you will get a `Promise` inside `results`):
Since 3.0.0, tinyspy doesn't unwrap the Promise anymore, so you need to await it manually:

```js
const spied = spy(async (n) => n + '!')
Expand All @@ -72,9 +71,14 @@ console.log(spied.returns) // [Promise<'a!'>]

await promise

console.log(spied.returns) // ['a!']
console.log(spied.returns) // [Promise<'a!'>]

console.log(await spied.returns[0]) // 'a!'
```

> [!WARNING]
> This also means the function that returned a Promise will always have result type `'ok'` even if the Promise rejected
### spyOn

> All `spy` methods are available on `spyOn`.
Expand Down
2 changes: 1 addition & 1 deletion src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, define, defineValue, isPromise, isType } from './utils'
import { assert, define, defineValue, isType } from './utils'
import { S } from './constants'

interface GetState {
Expand Down

0 comments on commit 00b00ca

Please sign in to comment.