Skip to content

Commit

Permalink
plugin-select-readme Describe how to mock a selector return value
Browse files Browse the repository at this point in the history
  • Loading branch information
corvidism committed Jul 19, 2024
1 parent c729abe commit 1680f5f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/plugin-select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,35 @@ The first one is setCreatorOfStateSelector where you can redefine your own selec

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).

## How to mock in tests

To test a component wrapped in `select`, mock `context.$Utils.$PermissionValidator.getState()` and `context.$Utils.$Dispatcher.listen()`.

Example:

```js
const context = {
$Utils: {
$PermissionValidator: {
hasPermission: hasPermissionMock,
},
$PageStateManager: {
getState: jest.fn(),
},
$Dispatcher: {
listen: () => {}
},
},
};

const setup = setupMountFactory(AuthedComponent, context);
const wrapper = setup(props);

context.$Utils.$PageStateManager.getState.mockReturnValue({foo: 'bar'})

```


## IMA.js

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

0 comments on commit 1680f5f

Please sign in to comment.