Skip to content

Commit 1680f5f

Browse files
committed
plugin-select-readme Describe how to mock a selector return value
1 parent c729abe commit 1680f5f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/plugin-select/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,35 @@ The first one is setCreatorOfStateSelector where you can redefine your own selec
118118

119119
The second one is setHoistStaticMethod where you can override [hoist-non-react-statics](https://www.npmjs.com/package/hoist-non-react-statics) module like [example](https://github.com/seznam/IMA.js-plugins/blob/master/packages/plugin-select/src/select/__tests__/SelectSpec.js#L155).
120120

121+
## How to mock in tests
122+
123+
To test a component wrapped in `select`, mock `context.$Utils.$PermissionValidator.getState()` and `context.$Utils.$Dispatcher.listen()`.
124+
125+
Example:
126+
127+
```js
128+
const context = {
129+
$Utils: {
130+
$PermissionValidator: {
131+
hasPermission: hasPermissionMock,
132+
},
133+
$PageStateManager: {
134+
getState: jest.fn(),
135+
},
136+
$Dispatcher: {
137+
listen: () => {}
138+
},
139+
},
140+
};
141+
142+
const setup = setupMountFactory(AuthedComponent, context);
143+
const wrapper = setup(props);
144+
145+
context.$Utils.$PageStateManager.getState.mockReturnValue({foo: 'bar'})
146+
147+
```
148+
149+
121150
## IMA.js
122151

123152
The [IMA.js](https://imajs.io) is an application development stack for developing

0 commit comments

Comments
 (0)