Skip to content

Commit

Permalink
plugin-select-readme Use Enzyme mount instead of cusom helper tool
Browse files Browse the repository at this point in the history
  • Loading branch information
corvidism committed Jul 22, 2024
1 parent 1680f5f commit 8062bc3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/plugin-select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,17 @@ The second one is setHoistStaticMethod where you can override [hoist-non-react-s

## How to mock in tests

To test a component wrapped in `select`, mock `context.$Utils.$PermissionValidator.getState()` and `context.$Utils.$Dispatcher.listen()`.
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: {
$PermissionValidator: {
hasPermission: hasPermissionMock,
},
$PageStateManager: {
getState: jest.fn(),
},
Expand All @@ -139,8 +140,13 @@ const context = {
},
};

const setup = setupMountFactory(AuthedComponent, context);
const wrapper = setup(props);
const wrapper = mount(
React.createElement(
PageContext.Provider,
{ value: context },
React.createElement(MyComponent, { permissions })
)
);

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

Expand Down

0 comments on commit 8062bc3

Please sign in to comment.