Skip to content

Commit b855e16

Browse files
committed
Re-add test for a custom store as a prop
1 parent 01ce9bd commit b855e16

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/components/connect.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe('React', () => {
103103
const store = createStore(() => ({ hi: 'there' }))
104104

105105
const Container = React.memo(props => <Passthrough {...props} />) // eslint-disable-line
106+
Container.displayName = 'Container'
106107
const WrappedContainer = connect(state => state)(Container)
107108

108109
const tester = rtl.render(
@@ -137,6 +138,7 @@ describe('React', () => {
137138
<Container pass="through" baz={50} />
138139
</ProviderMock>
139140
)
141+
140142
expect(tester.getByTestId('pass')).toHaveTextContent('through')
141143
expect(tester.getByTestId('foo')).toHaveTextContent('bar')
142144
expect(tester.getByTestId('baz')).toHaveTextContent('42')
@@ -1610,6 +1612,32 @@ describe('React', () => {
16101612
expect(actualState).toEqual(expectedState)
16111613
})
16121614

1615+
it('should use the store from the props instead of from the context if present', () => {
1616+
class Container extends Component {
1617+
render() {
1618+
return <Passthrough />
1619+
}
1620+
}
1621+
1622+
let actualState
1623+
1624+
const expectedState = { foos: {} }
1625+
const decorator = connect(state => {
1626+
actualState = state
1627+
return {}
1628+
})
1629+
const Decorated = decorator(Container)
1630+
const mockStore = {
1631+
dispatch: () => {},
1632+
subscribe: () => {},
1633+
getState: () => expectedState
1634+
}
1635+
1636+
rtl.render(<Decorated store={mockStore} />)
1637+
1638+
expect(actualState).toEqual(expectedState)
1639+
})
1640+
16131641
it('should use a custom context provider and consumer if passed as a prop to the component', () => {
16141642
class Container extends Component {
16151643
render() {

0 commit comments

Comments
 (0)