Skip to content

Commit

Permalink
docs: improve spyOn example with a contextual example (#3185)
Browse files Browse the repository at this point in the history
  • Loading branch information
bencodezen committed Apr 12, 2023
1 parent 29eebf6 commit aa22f79
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/api/vi.md
Expand Up @@ -567,14 +567,14 @@ IntersectionObserver === undefined

```ts
let apples = 0
const obj = {
const cart = {
getApples: () => 13,
}

const spy = vi.spyOn(obj, 'getApples').mockImplementation(() => apples)
const spy = vi.spyOn(cart, 'getApples').mockImplementation(() => apples)
apples = 1

expect(obj.getApples()).toBe(1)
expect(cart.getApples()).toBe(1)

expect(spy).toHaveBeenCalled()
expect(spy).toHaveReturnedWith(1)
Expand Down

0 comments on commit aa22f79

Please sign in to comment.