-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathvuex.js
48 lines (37 loc) · 1.42 KB
/
vuex.js
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
import 'jest-dom/extend-expect'
import VuexTest from './components/VuexTest'
import { render, fireEvent } from '@testing-library/vue'
const store = {
state: {
count: 0
},
actions: {
increment: ({ commit, state }) => commit('SET_COUNT', state.count + 1),
decrement: ({ commit, state }) => commit('SET_COUNT', state.count - 1)
},
mutations: {
SET_COUNT: (state, count) => { state.count = count }
}
}
test('can render with vuex with defaults', async () => {
const { getByTestId, getByText } = render(VuexTest, { store })
await fireEvent.click(getByText('+'))
expect(getByTestId('count-value')).toHaveTextContent('1')
})
test('can render with vuex with custom initial state', async () => {
store.state.count = 3
const { getByTestId, getByText } = render(VuexTest, { store })
await fireEvent.click(getByText('-'))
expect(getByTestId('count-value')).toHaveTextContent('2')
})
test('can render with vuex with custom store', async () => {
// this is a silly store that can never be changed
jest.spyOn(console, 'error').mockImplementation(() => {})
const store = { state: { count: 1000 } }
const { getByTestId, getByText } = render(VuexTest, { store })
await fireEvent.click(getByText('+'))
expect(getByTestId('count-value')).toHaveTextContent('1000')
await fireEvent.click(getByText('-'))
expect(getByTestId('count-value')).toHaveTextContent('1000')
expect(console.error).toHaveBeenCalled()
})