-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathvuex.spec.ts
73 lines (62 loc) · 1.41 KB
/
vuex.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, expect, test } from 'vitest'
import { defineComponent } from 'vue'
import { createStore, useStore } from 'vuex'
import { mount } from '../../src'
describe('vuex', () => {
test('renders a component using a vuex store', async () => {
const Foo = defineComponent({
template: `
<div>
count: {{ $store.state.count }}
<button @click="$store.dispatch('inc')" />
</div>
`
})
const store = createStore({
state: {
count: 1
},
mutations: {
INC(state) {
state.count += 1
}
},
actions: {
inc(context) {
context.commit('INC')
}
}
})
const wrapper = mount(Foo, {
global: {
plugins: [store]
}
})
await wrapper.find('button').trigger('click')
expect(wrapper.html()).toContain('count: 2')
})
test('works with an injection key and composition API', () => {
const store = createStore({
state() {
return {
count: 1
}
}
})
const key = Symbol()
const Foo = defineComponent({
template: `<div>count: {{ store.state.count }}</div>`,
setup() {
return {
store: useStore(key)
}
}
})
const wrapper = mount(Foo, {
global: {
plugins: [[store, key]]
}
})
expect(wrapper.html()).toContain('count: 1')
})
})