@@ -25,6 +25,30 @@ describe('React', () => {
2525 }
2626 }
2727
28+ class ContextBoundStore {
29+ constructor ( reducer ) {
30+ this . reducer = reducer
31+ this . listeners = [ ]
32+ this . state = undefined
33+ this . dispatch ( { } )
34+ }
35+
36+ getState ( ) {
37+ return this . state
38+ }
39+
40+ subscribe ( listener ) {
41+ this . listeners . push ( listener )
42+ return ( ( ) => this . listeners . filter ( l => l !== listener ) )
43+ }
44+
45+ dispatch ( action ) {
46+ this . state = this . reducer ( this . getState ( ) , action )
47+ this . listeners . forEach ( l => l ( ) )
48+ return action
49+ }
50+ }
51+
2852 ProviderMock . childContextTypes = {
2953 store : PropTypes . object . isRequired
3054 }
@@ -134,6 +158,30 @@ describe('React', () => {
134158 expect ( stub . props . string ) . toBe ( 'ab' )
135159 } )
136160
161+ it ( 'should retain the store\'s context' , ( ) => {
162+ const store = new ContextBoundStore ( stringBuilder )
163+
164+ let Container = connect (
165+ state => ( { string : state } )
166+ ) ( function Container ( props ) {
167+ return < Passthrough { ...props } />
168+ } )
169+
170+ const spy = expect . spyOn ( console , 'error' )
171+ const tree = TestUtils . renderIntoDocument (
172+ < ProviderMock store = { store } >
173+ < Container />
174+ </ ProviderMock >
175+ )
176+ spy . destroy ( )
177+ expect ( spy . calls . length ) . toBe ( 0 )
178+
179+ const stub = TestUtils . findRenderedComponentWithType ( tree , Passthrough )
180+ expect ( stub . props . string ) . toBe ( '' )
181+ store . dispatch ( { type : 'APPEND' , body : 'a' } )
182+ expect ( stub . props . string ) . toBe ( 'a' )
183+ } )
184+
137185 it ( 'should handle dispatches before componentDidMount' , ( ) => {
138186 const store = createStore ( stringBuilder )
139187
0 commit comments