Skip to content

Commit

Permalink
Fix tests around custom context
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Nov 6, 2018
1 parent c9d5973 commit 58dcf33
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ describe('React', () => {
expect(decorated.foo).toBe('bar')
})

it('should use a custom context provider and consumer if present', () => {
it('should use a custom context provider and consumer if given as an option to connect', () => {
class Container extends Component {
render() {
return <Passthrough />
Expand All @@ -1484,18 +1484,59 @@ describe('React', () => {
let actualState

const expectedState = { foos: {} }
const ignoredState = {bars : {} }

const decorator = connect(state => {
actualState = state
return {}
}, undefined, undefined, { context })
const Decorated = decorator(Container)
const mockStore = {
dispatch: () => {},
subscribe: () => {},
getState: () => expectedState

const store1 = createStore(() => expectedState);
const store2 = createStore(() => ignoredState);

rtl.render(
<ProviderMock context={context} store={store1}>
<ProviderMock store={store2}>
<Decorated />
</ProviderMock>
</ProviderMock>
)

expect(actualState).toEqual(expectedState)
})


it('should use a custom context provider and consumer if passed as a prop to the component', () => {
class Container extends Component {
render() {
return <Passthrough />
}
}

rtl.render(<ProviderMock context={context} store={mockStore}><Decorated context={context} /></ProviderMock>)
const context = React.createContext(null)

let actualState

const expectedState = { foos: {} }
const ignoredState = {bars : {} }

const decorator = connect(state => {
actualState = state
return {}
})
const Decorated = decorator(Container)

const store1 = createStore(() => expectedState);
const store2 = createStore(() => ignoredState);

rtl.render(
<ProviderMock context={context} store={store1}>
<ProviderMock store={store2}>
<Decorated context={context} />
</ProviderMock>
</ProviderMock>
)

expect(actualState).toEqual(expectedState)
})
Expand Down

0 comments on commit 58dcf33

Please sign in to comment.