私はreact-dom/test-utils
を使用して反応成分をテストします。react-dom/test-utils、TypeError:未定義の 'children'プロパティを読み取れません
しかしscryRenderedDOMComponentsWithClass
の戻り値にはprops
とprops.children
性質を持っていません。私は何か間違ったことをやったのですか?ここ
は私のテストコードです:ここ
it('renders item count correctly',() => {
const $$searchList = TestUtils.renderIntoDocument(<SearchList items={datas}/>)
const list = TestUtils.scryRenderedDOMComponentsWithClass($$searchList, 'list');
expect(list.props.children).toHaveLength(4);
expect(items).toHaveLength(4);
});
は、テスト結果です:
● component - SearchList test suites › renders item count correctly
TypeError: Cannot read property 'children' of undefined
at Object.<anonymous> (src/components/List/__tests__/SearchList.test.jsx:17:26)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
at process._tickCallback (internal/process/next_tick.js:109:7)
component - SearchList test suites
✓ loads without error (43ms)
✕ renders item count correctly (18ms)
- アップデート -
ここでは私のコンポーネントによってレンダリングされる:
return (
<div className="list">
{
items.map((item: Book, idx: number): React.ReactElement<IListProps<Book>> => {
return (
<ListItem onClick={() => this.onItemClick(item, idx)} key={item.id} item={item}/>
);
})
}
</div>
);
を
私は私の質問を更新しますが、まだやり方は分かりません。 – novaline