是否可以定义一个包含字符串格式信息的接口?请看以下示例:
interface timeMarkers{
markerTime: string[]
};
Run Code Online (Sandbox Code Playgroud)
一个例子是:
{
markerTime: ["0:00","1:30", "1:48"]
}
Run Code Online (Sandbox Code Playgroud)
我的问题:有没有办法定义类型markerTime,以便字符串值必须始终匹配此正则表达式,而不是简单地声明它string[]并从那里开始?
var reg = /[0-9]?[0-9]:[0-9][0-9]/;
我有一个测试用例。该项目正在使用@testing-library/react
it('renders content if loading is false', async () => {
await waitFor(() => {
render(<Loader loading={false}><span>foo</span></Loader>);
});
const loaderElementText = screen.getByText('Loading');
expect(loaderElementText).not.toBeInTheDocument();
const contentText = screen.getByText('foo');
expect(contentText).toBeInTheDocument();
});
Run Code Online (Sandbox Code Playgroud)
它不允许我运行expect(loaderElementText).not.toBeInTheDocument();带有以下错误的行:
TestingLibraryElementError: Unable to find an element with the text: Loading. 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.
Run Code Online (Sandbox Code Playgroud)
反向测试用例按loading={true}预期工作。
我已经无计可施了。查询文档中的元素并期望找不到该元素的语法是什么?