reactjs - React 测试库 - 无法找到带有文本的元素
问题描述
我希望测试确保子组件未呈现。
这是我的测试:
test(' Renders not render upload-model step for other impl type', () => {
render(<StepSelector />, {
initialState: { implOnboard: { ...initialState, onboardType: 'SOMETHING_ELSE' } },
});
expect(screen.getByText('Upload Model')).not.toBeDefined();
});
零件
const renderSecondStep = () => {
switch (onboardType) {
case IMPL_TYPES.PRE_TRAINED:
return (
<StepBox
completedSteps={0}
totalSteps={1}
stepNumber={2}
title="Upload Model"
active={true}
data-testid="upload-model"
/>
);
default:
return <React.Fragment></React.Fragment>; //
}
};
错误
TestingLibraryElementError: Unable to find an element with
the text: Upload Model. This could be because the text is broken up by multiple elements.
In this case, you can provide a function for your text matcher to make your matcher more flexible.
解决方案
推荐阅读
- c# - 如何将 Web API(已部署 IIS)连接到 MSSQLLocalDB
- node.js - 如果使用 chai-sies / Mocha / Test 调用函数(节点模块),如何测试它
- html - 如何从我的 iframe 中获取点击监听器?
- mysql - 根据列和状态列的组合查询以获取记录
- unity3d - 加载我的场景时发生未知错误。统一
- automation - 如何使用 VBS 捕获命令窗口的输出并通过播放的声音通知用户?
- preview - 使用 azure Form Recognizer api v2.1 通过 REST 训练模型时提供自定义模型名称
- mysql - MySql查询不同的条件
- php - 从 MySQL 填充数据表中的数据:Php Ajax
- linux - 如何更新 Argo CLI?