-
-
Notifications
You must be signed in to change notification settings - Fork 980
/
devtools.spec.ts
36 lines (30 loc) 路 1.04 KB
/
devtools.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, defineStore } from '../src'
import { devtoolsPlugin } from '../src/devtools'
describe('devtoolsPlugin', () => {
const useStore = defineStore('test', {
actions: {
myAction() {
return 42
},
},
})
it('preserves mocked actions during testing', () => {
const pinia = createPinia()
// Simulate using createTestingPinia
pinia._testing = true
mount({ template: 'none' }, { global: { plugins: [pinia] } })
// Simulate mocking with @pinia/testing createSpy
pinia.use(({ store, options }) => {
Object.keys(options.actions).forEach((action) => {
store[action]._mockImplementation = () => {}
})
})
// Previously the mocked actions would be wrapped again
pinia.use(devtoolsPlugin)
const store = useStore(pinia)
// @ts-expect-error we have not actually loaded @pinia/testing and mocked actions
expect(store.myAction._mockImplementation).toBeDefined()
})
})