UNPKG

1.62 kBJavaScriptView Raw
1import React from 'react';
2import { mount } from 'enzyme';
3import { Provider } from 'react-redux';
4import configureStore from 'redux-mock-store';
5import { increase, decrease, double, counter } from './state';
6
7import App from './App';
8
9const mockStore = configureStore([]);
10const store = mockStore({ app: { counter: { value: 0 } } });
11
12describe('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