我正在使用 MUI System v5 开发一个新项目。我在这里使用styled()实用程序(不是样式组件)来设计和创建简单的 UI 组件。该项目采用 TypeScript。我现在有很多困难,因为我不知道是否以及如何将道具传递给这些组件。例如,我有一个这样的组件:
import { styled } from '@mui/system';
const InputField = styled('input')(({ width }) => ({
width: width
}));
Run Code Online (Sandbox Code Playgroud)
我想以这种方式使用它:
return <InputField width={100}>
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:
Property 'width' does not exist on type '{ theme?: Theme; as?: ElementType<any>; sx?: SxProps<Theme>; } & ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & { ...; }'.ts(2339)
所以我的问题是:如何为此类 Material UI 组件提供额外的 props?
在 Cypress 中,我试图计算有多少个元素(在这种情况下 li 中有多少个按钮)包含文本。当使用“contains”时,返回的项目数总是等于一个,因为“contains”只给出包含搜索文本的文档中的第一个项目。
cy.get('li')
.contains('button', 'Submit')
.its('length')
.then(elLength => {
// I want to test here the number of all buttons in li elements containig word 'Submit'
}
Run Code Online (Sandbox Code Playgroud)
当然,这不会那样工作,因为elLength始终为 1(如果未找到项目,则为0)。
Cypress 中有没有其他方法可以返回所有带有文本的元素,我可以计算它们?