Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin-select-readme Describe how to mock a selector return value #170

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading