我想使用react测试库呈现两个组件。
我有两个组件,即firstComponent和secondComponent
在我的测试中,我呈现了一个组件,如下所示
test('check test', async() => {
const { getByTestId } = utils.render(
<firstComp />,
[
utils.gqlMock(queryname, query-type),
]
);
//some logic here to do with getBytestid
)};现在的问题是如何在utils.render方法中使用模拟呈现组件secondComponent
我试过这样的东西
test('check test', async() => {
const { getByTestId } = utils.render(
<secondComp/>,
[ utils.gqlMock(queryname3, query-type3),
]
<firstComp />,
[
utils.gqlMock(queryname, query-type),
]
);
//some logic here to do with getBytestid
)};但这会抛出一些错误。这似乎不是正确的方式。有人能帮我一下吗。谢谢。
发布于 2020-05-10 23:45:58
我从来没有这样做过,但我会尝试这样的东西:
const { getByTestId } = utils.render(
<>
<SecondComponent />
<FirstComponent />
</>,
[...]
);https://stackoverflow.com/questions/61678634
复制相似问题