Skip to content

Commit

Permalink
docs: add resolves property
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 17, 2024
1 parent ccbbae1 commit 0f87f85
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ console.log(spied.calls) // []
console.log(spied.returns) // []
```

Since 3.0.0, tinyspy doesn't unwrap the Promise anymore, so you need to await it manually:
Since 3.0, tinyspy doesn't unwrap the Promise in `returns` anymore, so you need to await it manually:

```js
const spied = spy(async (n) => n + '!')

const promise = spied('a')

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

await promise

Expand All @@ -79,6 +79,21 @@ 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
Tinyspy 3.0 still exposes resolved values on `resolves` property:

```js
const spied = spy(async (n) => n + '!')

const promise = spied('a')

console.log(spied.called) // true
console.log(spied.resolves) // [] <- not resolved yet

await promise

console.log(spied.resolves) // ['ok', 'a!']
```

### spyOn

> All `spy` methods are available on `spyOn`.
Expand Down

0 comments on commit 0f87f85

Please sign in to comment.