Skip to content

Commit

Permalink
docs: example for vitest
Browse files Browse the repository at this point in the history
See #2464
  • Loading branch information
posva committed Oct 29, 2023
1 parent 71c28ad commit 40f8f22
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/docs/cookbook/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,29 @@ expect(store.someAction).toHaveBeenCalledTimes(1)

### Specifying the createSpy function

When using Jest, or vitest with `globals: true`, `createTestingPinia` automatically stubs actions using the spy function based on the existing test framework (`jest.fn` or `vitest.fn`). If you are using a different framework, you'll need to provide a [createSpy](/api/interfaces/pinia_testing.TestingOptions.html#createspy) option:
When using Jest, or vitest with `globals: true`, `createTestingPinia` automatically stubs actions using the spy function based on the existing test framework (`jest.fn` or `vitest.fn`). If you are not using `globals: true` or using a different framework, you'll need to provide a [createSpy](/api/interfaces/pinia_testing.TestingOptions.html#createspy) option:

```js
::: code-group

```ts [vitest]
// NOTE: not needed with `globals: true`
import { vi } from 'vitest'

createTestingPinia({
createSpy: vi.fn,
})
```

```ts [sinon]
import sinon from 'sinon'

createTestingPinia({
createSpy: sinon.spy, // use sinon's spy to wrap actions
createSpy: sinon.spy,
})
```

:::

You can find more examples in [the tests of the testing package](https://github.com/vuejs/pinia/blob/v2/packages/testing/src/testing.spec.ts).

### Mocking getters
Expand Down

0 comments on commit 40f8f22

Please sign in to comment.