Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.

Commit f65a7bb

Browse files
committed
Added test for custom subspace context
1 parent 56e3492 commit f65a7bb

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/redux-dynostore-react-redux-subspace/test/subspaced.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,54 @@ describe('mapExtraState tests', () => {
276276
).toThrow(TypeError)
277277
})
278278
})
279+
280+
describe('subspaceOptions tests', () => {
281+
const mockStore = configureStore([])
282+
let store
283+
284+
const CustomContext = React.createContext()
285+
286+
class TestComponent extends React.Component {
287+
render() {
288+
return <p>{this.props.testKey}</p>
289+
}
290+
}
291+
292+
const mapStateToProps = state => ({
293+
testKey: state.testKey
294+
})
295+
296+
const ConnectedTestComponent = connect(
297+
mapStateToProps,
298+
null,
299+
null,
300+
{ context: CustomContext }
301+
)(TestComponent)
302+
303+
beforeEach(() => {
304+
store = mockStore({
305+
testId: {
306+
testKey: 'root value'
307+
},
308+
parentId: {
309+
testId: {
310+
testKey: 'nested value'
311+
}
312+
}
313+
})
314+
})
315+
316+
test('should create subspaced enhanced component using custom context', () => {
317+
const SubspacedComponent = subspaced({ context: CustomContext })('testId')(store)(ConnectedTestComponent)
318+
319+
const { getByText } = render(
320+
<Provider store={store} context={CustomContext}>
321+
<SubspaceProvider mapState={state => state.parentId} namespace="parentId" context={CustomContext}>
322+
<SubspacedComponent />
323+
</SubspaceProvider>
324+
</Provider>
325+
)
326+
327+
expect(getByText('nested value')).toBeDefined()
328+
})
329+
})

0 commit comments

Comments
 (0)