]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: example for vitest
authorEduardo San Martin Morote <posva13@gmail.com>
Sun, 29 Oct 2023 09:16:33 +0000 (10:16 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Sun, 29 Oct 2023 09:16:33 +0000 (10:16 +0100)
See https://github.com/vuejs/pinia/discussions/2464

packages/docs/cookbook/testing.md

index d125daa84ce69b00758b87d71bba426eb1350cae..29261eb66d25c3341615c178504353e1e1469424 100644 (file)
@@ -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