1 | import React from 'react';
|
2 | import { mount } from 'enzyme';
|
3 | import { Provider } from 'react-redux';
|
4 | import configureStore from 'redux-mock-store';
|
5 | import { increase, decrease, double, counter } from './state';
|
6 |
|
7 | import App from './App';
|
8 |
|
9 | const mockStore = configureStore([]);
|
10 | const store = mockStore({ app: { counter: { value: 0 } } });
|
11 |
|
12 | describe('App', () => {
|
13 | it('renders correctly', () => {
|
14 | mount(<App store={store} />);
|
15 | });
|
16 | it('should contain one "H2" element', () => {
|
17 | expect(mount(<Provider store={store}><App /></Provider>).find('h2').length).toBe(1);
|
18 | });
|
19 | it('should contain three "button" elements', () => {
|
20 | expect(mount(<Provider store={store}><App /></Provider>).find('button').length).toBe(3);
|
21 | });
|
22 | it('should dispatch increase action', () => {
|
23 | store.dispatch(increase());
|
24 | expect(store.getActions()).toEqual([{ type: 'INCREMENT' }]);
|
25 | });
|
26 | it('should dispatch decrease action', () => {
|
27 | store.clearActions();
|
28 | store.dispatch(decrease());
|
29 | expect(store.getActions()).toEqual([{ type: 'DECREMENT' }]);
|
30 | });
|
31 | it('should dispatch double action', () => {
|
32 | store.clearActions();
|
33 | store.dispatch(double());
|
34 | expect(store.getActions()).toEqual([{ type: 'DUPLICATION' }]);
|
35 | });
|
36 | it('should increase counter', () => {
|
37 | expect(counter({ value: 1 }, { type: 'INCREMENT' })).toEqual({ value: 2 });
|
38 | });
|
39 | it('should decrease counter', () => {
|
40 | expect(counter({ value: 1 }, { type: 'DECREMENT' })).toEqual({ value: 0 });
|
41 | });
|
42 | it('should double counter', () => {
|
43 | expect(counter({ value: 3 }, { type: 'DUPLICATION' })).toEqual({ value: 6 });
|
44 | });
|
45 | });
|
46 |
|
\ | No newline at end of file |