我正在页面中的某个部分使用区域角色。
它由 aria 标签描述,说明该部分的作用。
我正在编写单元测试以确保该部分存在,如codesandbox中所示。
你好组件:
export default ({ name }) => <h1>Hello {name}!</h1>;
测试:
test("region described by hello region should exists in the dom", () => {
const { getByText, getByRole } = render(<Hello name="Jill" />);
expect(
getByRole("region", { description: "hello region" })
).toBeInTheDocument();
});
您的测试应该适用于
expect(getByRole('heading')).toHaveTextContent("hello region");