[英]Jest test open react-select menu
I have a component that uses react-select.我有一个使用 react-select 的组件。 I want to test the correct props are being passed to it, and those are being displayed correctly.我想测试传递给它的正确道具,并且这些道具是否正确显示。 Is there anyway to force the menu to open in enzyme/jest?反正有没有强制菜单在酶/笑话中打开?
You can force change the state of the internal StateManager
component您可以强制更改内部StateManager
组件的状态
const tree = mount(<MyComponent />);
tree.find('Select').find('StateManager').instance().setState({ menuIsOpen: true });
tree.update();
Alternatively, a better way is to check the props of the component without opening the Select menu.或者,更好的方法是在不打开 Select 菜单的情况下检查组件的 props。 This let's you abstract out react-select better in your tests.这让您可以在测试中更好地抽象出 react-select。
const tree = mount(<MyComponent />);
// Run tests against options prop of Select
// expect(tree.find('Select').props('options')).toHaveLength(10);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.