Skip to content

Commit

Permalink
Merge pull request #170 from seznam/plugin-select-readme
Browse files Browse the repository at this point in the history
plugin-select-readme Describe how to mock a selector return value
  • Loading branch information
mjancarik authored Jul 23, 2024
2 parents b226a22 + 23d41ec commit d136fbd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/plugin-select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,43 @@ 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.$PageStateManager.getState()` and `context.$Utils.$Dispatcher.listen()`.

Example:

```js

import { mount } from 'enzyme';
import { PageContext } from '@ima/react-page-renderer';

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

//..

const wrapper = mount(
React.createElement(
PageContext.Provider,
{ value: context },
React.createElement(MyComponent, 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 d136fbd

Please sign in to comment.