|
1 |
| -test.todo('Your test suite must contain at least one test.') |
2 |
| - |
3 |
| -// import '@testing-library/jest-dom' |
4 |
| -// import {render, fireEvent} from '@testing-library/vue' |
5 |
| - |
6 |
| -// import VuexTest from './components/Store/VuexTest' |
7 |
| -// import {store} from './components/Store/store' |
8 |
| - |
9 |
| -// // A common testing pattern is to create a custom renderer for a specific test |
10 |
| -// // file. This way, common operations such as registering a Vuex store can be |
11 |
| -// // abstracted out while avoiding sharing mutable state. |
12 |
| -// // |
13 |
| -// // Tests should be completely isolated from one another. |
14 |
| -// // Read this for additional context: https://kentcdodds.com/blog/test-isolation-with-react |
15 |
| -// function renderVuexTestComponent(customStore) { |
16 |
| -// // Render the component and merge the original store and the custom one |
17 |
| -// // provided as a parameter. This way, we can alter some behaviors of the |
18 |
| -// // initial implementation. |
19 |
| -// return render(VuexTest, {store: {...store, ...customStore}}) |
20 |
| -// } |
21 |
| - |
22 |
| -// test('can render with vuex with defaults', async () => { |
23 |
| -// const {getByTestId, getByText} = renderVuexTestComponent() |
24 |
| -// await fireEvent.click(getByText('+')) |
25 |
| - |
26 |
| -// expect(getByTestId('count-value')).toHaveTextContent('1') |
27 |
| -// }) |
28 |
| - |
29 |
| -// test('can render with vuex with custom initial state', async () => { |
30 |
| -// const {getByTestId, getByText} = renderVuexTestComponent({ |
31 |
| -// state: {count: 3}, |
32 |
| -// }) |
33 |
| -// await fireEvent.click(getByText('-')) |
34 |
| - |
35 |
| -// expect(getByTestId('count-value')).toHaveTextContent('2') |
36 |
| -// }) |
37 |
| - |
38 |
| -// test('can render with vuex with custom store', async () => { |
39 |
| -// // This is a silly store that can never be changed. |
40 |
| -// // eslint-disable-next-line no-shadow |
41 |
| -// const store = { |
42 |
| -// state: {count: 1000}, |
43 |
| -// actions: { |
44 |
| -// increment: () => jest.fn(), |
45 |
| -// decrement: () => jest.fn(), |
46 |
| -// }, |
47 |
| -// } |
48 |
| - |
49 |
| -// // Notice how here we are not using the helper method, because there's no |
50 |
| -// // need to do that. |
51 |
| -// const {getByTestId, getByText} = render(VuexTest, {store}) |
52 |
| - |
53 |
| -// await fireEvent.click(getByText('+')) |
54 |
| -// expect(getByTestId('count-value')).toHaveTextContent('1000') |
55 |
| - |
56 |
| -// await fireEvent.click(getByText('-')) |
57 |
| -// expect(getByTestId('count-value')).toHaveTextContent('1000') |
58 |
| -// }) |
| 1 | + import '@testing-library/jest-dom' |
| 2 | + import {render, fireEvent} from '@testing-library/vue' |
| 3 | + import VuexTest from './components/Store/VuexTest' |
| 4 | + import {store} from './components/Store/store' |
| 5 | + |
| 6 | + // A common testing pattern is to create a custom renderer for a specific test |
| 7 | + // file. This way, common operations such as registering a Vuex store can be |
| 8 | + // abstracted out while avoiding sharing mutable state. |
| 9 | + // |
| 10 | + // Tests should be completely isolated from one another. |
| 11 | + // Read this for additional context: https://kentcdodds.com/blog/test-isolation-with-react |
| 12 | + function renderVuexTestComponent(customStore) { |
| 13 | + // Render the component and merge the original store and the custom one |
| 14 | + // provided as a parameter. This way, we can alter some behaviors of the |
| 15 | + // initial implementation. |
| 16 | + return render(VuexTest, {store: {...store, ...customStore}}) |
| 17 | + } |
| 18 | + |
| 19 | + test('can render with vuex with defaults', async () => { |
| 20 | + const {getByTestId, getByText} = renderVuexTestComponent() |
| 21 | + |
| 22 | + await fireEvent.click(getByText('+')) |
| 23 | + |
| 24 | + expect(getByTestId('count-value')).toHaveTextContent('1') |
| 25 | + }) |
| 26 | + |
| 27 | + test('can render with vuex with custom initial state', async () => { |
| 28 | + const {getByTestId, getByText} = renderVuexTestComponent({ |
| 29 | + state: {count: 3}, |
| 30 | + }) |
| 31 | + |
| 32 | + await fireEvent.click(getByText('-')) |
| 33 | + |
| 34 | + expect(getByTestId('count-value')).toHaveTextContent('2') |
| 35 | + }) |
| 36 | + |
| 37 | + test('can render with vuex with custom store', async () => { |
| 38 | + // This is a silly store that can never be changed. |
| 39 | + // eslint-disable-next-line no-shadow |
| 40 | + const store = { |
| 41 | + state: {count: 1000}, |
| 42 | + actions: { |
| 43 | + increment: () => jest.fn(), |
| 44 | + decrement: () => jest.fn(), |
| 45 | + }, |
| 46 | + } |
| 47 | + |
| 48 | + // Notice how here we are not using the helper rendering method, because |
| 49 | + // there's no need to do that here. We're passing a whole store. |
| 50 | + const {getByTestId, getByText} = render(VuexTest, {store}) |
| 51 | + |
| 52 | + await fireEvent.click(getByText('+')) |
| 53 | + expect(getByTestId('count-value')).toHaveTextContent('1000') |
| 54 | + |
| 55 | + await fireEvent.click(getByText('-')) |
| 56 | + expect(getByTestId('count-value')).toHaveTextContent('1000') |
| 57 | + }) |
0 commit comments