Skip to content

Commit 58dcf33

Browse files
committed
Fix tests around custom context
1 parent c9d5973 commit 58dcf33

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

test/components/connect.spec.js

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ describe('React', () => {
14721472
expect(decorated.foo).toBe('bar')
14731473
})
14741474

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', () => {
14761476
class Container extends Component {
14771477
render() {
14781478
return <Passthrough />
@@ -1484,18 +1484,59 @@ describe('React', () => {
14841484
let actualState
14851485

14861486
const expectedState = { foos: {} }
1487+
const ignoredState = {bars : {} }
1488+
14871489
const decorator = connect(state => {
14881490
actualState = state
14891491
return {}
14901492
}, undefined, undefined, { context })
14911493
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+
}
14961515
}
14971516

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+
)
14991540

15001541
expect(actualState).toEqual(expectedState)
15011542
})

0 commit comments

Comments
 (0)