1+ /* global store */
12import React from 'react'
23import renderer from 'react-test-renderer'
34
45import createStore from '../'
56
6- const config = {
7- initialState : {
8- count : 0 ,
9- } ,
10- actionsCreators : {
11- increment : ( { count } ) => ( { count : count + 1 } ) ,
12- } ,
13- }
14-
157global . 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
2730test ( '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
4042test ( '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