1
- import expect from 'expect' ;
2
- import React , { PropTypes , Component } from 'react' ;
3
- import TestUtils from 'react-addons-test-utils' ;
4
- import { createStore } from 'redux' ;
5
- import { Provider } from '../../src/index' ;
1
+ import expect from 'expect'
2
+ import React , { PropTypes , Component } from 'react'
3
+ import TestUtils from 'react-addons-test-utils'
4
+ import { createStore } from 'redux'
5
+ import { Provider } from '../../src/index'
6
6
7
7
describe ( 'React' , ( ) => {
8
8
describe ( 'Provider' , ( ) => {
@@ -12,97 +12,97 @@ describe('React', () => {
12
12
}
13
13
14
14
render ( ) {
15
- return < div /> ;
15
+ return < div />
16
16
}
17
17
}
18
18
19
19
it ( 'should enforce a single child' , ( ) => {
20
- const store = createStore ( ( ) => ( { } ) ) ;
20
+ const store = createStore ( ( ) => ( { } ) )
21
21
22
22
// Ignore propTypes warnings
23
- const propTypes = Provider . propTypes ;
24
- Provider . propTypes = { } ;
23
+ const propTypes = Provider . propTypes
24
+ Provider . propTypes = { }
25
25
26
26
try {
27
27
expect ( ( ) => TestUtils . renderIntoDocument (
28
28
< Provider store = { store } >
29
29
< div />
30
30
</ Provider >
31
- ) ) . toNotThrow ( ) ;
31
+ ) ) . toNotThrow ( )
32
32
33
33
expect ( ( ) => TestUtils . renderIntoDocument (
34
34
< Provider store = { store } >
35
35
</ Provider >
36
- ) ) . toThrow ( / e x a c t l y o n e c h i l d / ) ;
36
+ ) ) . toThrow ( / e x a c t l y o n e c h i l d / )
37
37
38
38
expect ( ( ) => TestUtils . renderIntoDocument (
39
39
< Provider store = { store } >
40
40
< div />
41
41
< div />
42
42
</ Provider >
43
- ) ) . toThrow ( / e x a c t l y o n e c h i l d / ) ;
43
+ ) ) . toThrow ( / e x a c t l y o n e c h i l d / )
44
44
} finally {
45
- Provider . propTypes = propTypes ;
45
+ Provider . propTypes = propTypes
46
46
}
47
- } ) ;
47
+ } )
48
48
49
49
it ( 'should add the store to the child context' , ( ) => {
50
- const store = createStore ( ( ) => ( { } ) ) ;
50
+ const store = createStore ( ( ) => ( { } ) )
51
51
52
- const spy = expect . spyOn ( console , 'error' ) ;
52
+ const spy = expect . spyOn ( console , 'error' )
53
53
const tree = TestUtils . renderIntoDocument (
54
54
< Provider store = { store } >
55
55
< Child />
56
56
</ Provider >
57
- ) ;
58
- spy . destroy ( ) ;
59
- expect ( spy . calls . length ) . toBe ( 0 ) ;
57
+ )
58
+ spy . destroy ( )
59
+ expect ( spy . calls . length ) . toBe ( 0 )
60
60
61
- const child = TestUtils . findRenderedComponentWithType ( tree , Child ) ;
62
- expect ( child . context . store ) . toBe ( store ) ;
63
- } ) ;
61
+ const child = TestUtils . findRenderedComponentWithType ( tree , Child )
62
+ expect ( child . context . store ) . toBe ( store )
63
+ } )
64
64
65
65
it ( 'should warn once when receiving a new store in props' , ( ) => {
66
- const store1 = createStore ( ( state = 10 ) => state + 1 ) ;
67
- const store2 = createStore ( ( state = 10 ) => state * 2 ) ;
68
- const store3 = createStore ( ( state = 10 ) => state * state ) ;
66
+ const store1 = createStore ( ( state = 10 ) => state + 1 )
67
+ const store2 = createStore ( ( state = 10 ) => state * 2 )
68
+ const store3 = createStore ( ( state = 10 ) => state * state )
69
69
70
70
class ProviderContainer extends Component {
71
- state = { store : store1 } ;
71
+ state = { store : store1 }
72
72
73
73
render ( ) {
74
74
return (
75
75
< Provider store = { this . state . store } >
76
76
< Child />
77
77
</ Provider >
78
- ) ;
78
+ )
79
79
}
80
80
}
81
81
82
- const container = TestUtils . renderIntoDocument ( < ProviderContainer /> ) ;
83
- const child = TestUtils . findRenderedComponentWithType ( container , Child ) ;
84
- expect ( child . context . store . getState ( ) ) . toEqual ( 11 ) ;
82
+ const container = TestUtils . renderIntoDocument ( < ProviderContainer /> )
83
+ const child = TestUtils . findRenderedComponentWithType ( container , Child )
84
+ expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
85
85
86
- let spy = expect . spyOn ( console , 'error' ) ;
87
- container . setState ( { store : store2 } ) ;
88
- spy . destroy ( ) ;
86
+ let spy = expect . spyOn ( console , 'error' )
87
+ container . setState ( { store : store2 } )
88
+ spy . destroy ( )
89
89
90
- expect ( child . context . store . getState ( ) ) . toEqual ( 11 ) ;
91
- expect ( spy . calls . length ) . toBe ( 1 ) ;
90
+ expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
91
+ expect ( spy . calls . length ) . toBe ( 1 )
92
92
expect ( spy . calls [ 0 ] . arguments [ 0 ] ) . toBe (
93
93
'<Provider> does not support changing `store` on the fly. ' +
94
94
'It is most likely that you see this error because you updated to ' +
95
95
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
96
96
'automatically. See https://github.com/rackt/react-redux/releases/' +
97
97
'tag/v2.0.0 for the migration instructions.'
98
- ) ;
98
+ )
99
99
100
- spy = expect . spyOn ( console , 'error' ) ;
101
- container . setState ( { store : store3 } ) ;
102
- spy . destroy ( ) ;
100
+ spy = expect . spyOn ( console , 'error' )
101
+ container . setState ( { store : store3 } )
102
+ spy . destroy ( )
103
103
104
- expect ( child . context . store . getState ( ) ) . toEqual ( 11 ) ;
105
- expect ( spy . calls . length ) . toBe ( 0 ) ;
106
- } ) ;
107
- } ) ;
108
- } ) ;
104
+ expect ( child . context . store . getState ( ) ) . toEqual ( 11 )
105
+ expect ( spy . calls . length ) . toBe ( 0 )
106
+ } )
107
+ } )
108
+ } )
0 commit comments