簡體   English   中英

Jest 測試打開 react-select 菜單

[英]Jest test open react-select menu

我有一個使用 react-select 的組件。 我想測試傳遞給它的正確道具,並且這些道具是否正確顯示。 反正有沒有強制菜單在酶/笑話中打開?

您可以強制更改內部StateManager組件的狀態

const tree = mount(<MyComponent />);
tree.find('Select').find('StateManager').instance().setState({ menuIsOpen: true });
tree.update();

或者,更好的方法是在不打開 Select 菜單的情況下檢查組件的 props。 這讓您可以在測試中更好地抽象出 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM