@@ -1472,7 +1472,7 @@ describe('React', () => {
1472
1472
expect ( decorated . foo ) . toBe ( 'bar' )
1473
1473
} )
1474
1474
1475
- it ( 'should use a custom context provider and consumer if present ' , ( ) => {
1475
+ it ( 'should use a custom context provider and consumer if given as an option to connect ' , ( ) => {
1476
1476
class Container extends Component {
1477
1477
render ( ) {
1478
1478
return < Passthrough />
@@ -1484,18 +1484,59 @@ describe('React', () => {
1484
1484
let actualState
1485
1485
1486
1486
const expectedState = { foos : { } }
1487
+ const ignoredState = { bars : { } }
1488
+
1487
1489
const decorator = connect ( state => {
1488
1490
actualState = state
1489
1491
return { }
1490
1492
} , undefined , undefined , { context } )
1491
1493
const Decorated = decorator ( Container )
1492
- const mockStore = {
1493
- dispatch : ( ) => { } ,
1494
- subscribe : ( ) => { } ,
1495
- getState : ( ) => expectedState
1494
+
1495
+ const store1 = createStore ( ( ) => expectedState ) ;
1496
+ const store2 = createStore ( ( ) => ignoredState ) ;
1497
+
1498
+ rtl . render (
1499
+ < ProviderMock context = { context } store = { store1 } >
1500
+ < ProviderMock store = { store2 } >
1501
+ < Decorated />
1502
+ </ ProviderMock >
1503
+ </ ProviderMock >
1504
+ )
1505
+
1506
+ expect ( actualState ) . toEqual ( expectedState )
1507
+ } )
1508
+
1509
+
1510
+ it ( 'should use a custom context provider and consumer if passed as a prop to the component' , ( ) => {
1511
+ class Container extends Component {
1512
+ render ( ) {
1513
+ return < Passthrough />
1514
+ }
1496
1515
}
1497
1516
1498
- rtl . render ( < ProviderMock context = { context } store = { mockStore } > < Decorated context = { context } /> </ ProviderMock > )
1517
+ const context = React . createContext ( null )
1518
+
1519
+ let actualState
1520
+
1521
+ const expectedState = { foos : { } }
1522
+ const ignoredState = { bars : { } }
1523
+
1524
+ const decorator = connect ( state => {
1525
+ actualState = state
1526
+ return { }
1527
+ } )
1528
+ const Decorated = decorator ( Container )
1529
+
1530
+ const store1 = createStore ( ( ) => expectedState ) ;
1531
+ const store2 = createStore ( ( ) => ignoredState ) ;
1532
+
1533
+ rtl . render (
1534
+ < ProviderMock context = { context } store = { store1 } >
1535
+ < ProviderMock store = { store2 } >
1536
+ < Decorated context = { context } />
1537
+ </ ProviderMock >
1538
+ </ ProviderMock >
1539
+ )
1499
1540
1500
1541
expect ( actualState ) . toEqual ( expectedState )
1501
1542
} )
0 commit comments