-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathredux-app-03.test.js
45 lines (33 loc) · 1.32 KB
/
redux-app-03.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
43
44
45
import 'jest-dom/extend-expect';
import 'react-testing-library/cleanup-after-each';
import React from 'react';
import {createStore, combineReducers} from 'redux';
import {Provider} from 'react-redux';
import {render, fireEvent} from 'react-testing-library';
import {ConnectedCounter, reducer} from '../src/redux-app';
// allow our user to pass in a store, otherwise create one using the app's reducer
const renderWithRedux = (
ui,
{initialState, store = createStore(reducer, initialState), ...options} = {}
) => {
const utils = render(<Provider store={store}>{ui}</Provider>, options);
return utils;
};
describe('ConnectedCounter', () => {
test('renders with redux defaults', () => {
const {getByText, getByTestId} = renderWithRedux(<ConnectedCounter />);
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 {getByText, getByTestId} = renderWithRedux(<ConnectedCounter />, {
initialState: {count: 3},
});
expect(getByTestId('count-value')).toHaveTextContent(3);
});
});