-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathredux-app-02.test.js
42 lines (33 loc) · 1.17 KB
/
redux-app-02.test.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
import 'jest-dom/extend-expect';
import 'react-testing-library/cleanup-after-each';
import React from 'react';
import {createStore} from 'redux';
import {Provider} from 'react-redux';
import {render, fireEvent} from 'react-testing-library';
import {ConnectedCounter, reducer} from '../src/redux-app';
describe('ConnectedCounter', () => {
test('renders with redux defaults', () => {
const store = createStore(reducer);
const {getByText, getByTestId} = render(
<Provider store={store}>
<ConnectedCounter />
</Provider>
);
expect(getByTestId('count-value')).toHaveTextContent(0);
const incButton = getByText('+');
const decButton = getByText('-');
fireEvent.click(incButton);
expect(getByTestId('count-value')).toHaveTextContent(1);
fireEvent.click(decButton);
expect(getByTestId('count-value')).toHaveTextContent(0);
});
test('can render with custom initial state', () => {
const store = createStore(reducer, {count: 3});
const {getByText, getByTestId} = render(
<Provider store={store}>
<ConnectedCounter />
</Provider>
);
expect(getByTestId('count-value')).toHaveTextContent(3);
});
});