Skip to content

Commit 9749c63

Browse files
author
Didier Franc
committed
Add count test
1 parent a391247 commit 9749c63

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

src/__test__/__snapshots__/index.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`actions triggered and state updated 1`] = `"0"`;
4+
5+
exports[`actions triggered and state updated 2`] = `"1"`;
6+
37
exports[`render provider with its children 1`] = `
48
<h1>
59
Children

src/__test__/index.test.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1+
/* global store */
12
import React from 'react'
23
import renderer from 'react-test-renderer'
34

45
import createStore from '../'
56

6-
const config = {
7-
initialState: {
8-
count: 0,
9-
},
10-
actionsCreators: {
11-
increment: ({ count }) => ({ count: count + 1 }),
12-
},
13-
}
14-
157
global.console = { error: jest.fn() }
168

17-
test('store initialization', () => {
18-
const store = createStore(config)
9+
beforeEach(() => {
10+
const config = {
11+
initialState: {
12+
count: 0,
13+
},
14+
actionsCreators: {
15+
increment: ({ count }) => ({ count: count + 1 }),
16+
},
17+
}
18+
19+
global.store = createStore(config)
20+
})
1921

22+
test('store initialization', () => {
2023
expect(store.Provider).toBeDefined()
2124
expect(store.connect).toBeDefined()
2225
expect(store.actions).toBeDefined()
@@ -25,8 +28,7 @@ test('store initialization', () => {
2528
})
2629

2730
test('render provider with its children', () => {
28-
const { Provider } = createStore(config)
29-
31+
const { Provider } = store
3032
const App = () => (
3133
<Provider>
3234
<h1>Children</h1>
@@ -38,7 +40,24 @@ test('render provider with its children', () => {
3840
})
3941

4042
test('call console.error if an action is called before Provider initialization', () => {
41-
const { actions } = createStore(config)
43+
const { actions } = store
4244
actions.increment()
4345
expect(console.error).toBeCalledWith('<Provider /> is not initialized yet')
4446
})
47+
48+
test('actions triggered and state updated', () => {
49+
const { Provider, connect, actions } = store
50+
51+
const Count = connect(({ count }) => ({ count }))(({ count }) => count)
52+
53+
const App = () => (
54+
<Provider>
55+
<Count />
56+
</Provider>
57+
)
58+
const tree = renderer.create(<App />)
59+
expect(tree.toJSON()).toMatchSnapshot()
60+
61+
actions.increment()
62+
expect(tree.toJSON()).toMatchSnapshot()
63+
})

0 commit comments

Comments
 (0)