diff --git a/README.md b/README.md index 91d4d79..656ad02 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # tinyspy > minimal fork of nanospy, with more features 🕵🏻‍♂️ @@ -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 + '!') @@ -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`. diff --git a/src/internal.ts b/src/internal.ts index 166546e..fe916c8 100644 --- a/src/internal.ts +++ b/src/internal.ts @@ -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 {