0

我正在使用 React 测试库进行 TDD。您可以使用正则表达式在您的 dom 中找到带标签的输入,如下所示:

import React from "react";
import { render } from "react-testing-library";
import App from "./App";

it("renders a first name input field", () => {
  const { getByLabel } = render(<App />);
  const actual = getByLabel(/username/i);
  expect(actual).toBeDefined();
});

我的问题是,在我的 UI 中有带有空格的标签,例如“名字”或“出生地”。如何使用正则表达式找到这些?

4

0 回答 0