测试特定的 MaterialUI 图标

Dy4*_*Dy4 5 reactjs jestjs material-ui react-testing-library

是否可以在特定的 Material UI 图标中作为 ArrowLeft / ArrowRight 而不是 .MuiSvgIcon-root 进行测试?

应用组件:

return {open ? <ArrowLeft/> :<ArrowRight/>}
Run Code Online (Sandbox Code Playgroud)

RTL 测试:下面的测试正在通过,但它不会检查特定的 ArrowLeft 或 ArrowRight 图标。

describes("MockTest",()=>{

it("renders Left arrow",()=>{
const {container} = renders(<App open={true}/>);
expect(container.querySelector(".MuiSvgIcon-root").toBeTruthy();
});

it("renders Right arrow",()=>{
const {container} = renders(<App open={false}/>);
expect(container.querySelector(".MuiSvgIcon-root").toBeTruthy();
});

});

Run Code Online (Sandbox Code Playgroud)

sli*_*wp2 1

对于RTL包来说这是不可能的。查看RTL 包作者的这篇文章。

RTL支持浅渲染。所以ArrowLeftandArrowRight总是会被渲染。