Reactjs 如何将react测试库类匹配器与scss模块一起使用?

Reactjs 如何将react测试库类匹配器与scss模块一起使用?,reactjs,react-testing-library,css-modules,Reactjs,React Testing Library,Css Modules,我有一个React组件,其背景颜色取决于传入的道具。例如,当舞台为“内部”时,我使用color-primary-light-10类设置背景色 我正在使用React测试库和Jest Dom测试是否应用了正确的颜色: it("should render internal stage using light primary color", () => { const {getByTestId} = render(<Background stage={"Internal"} />

我有一个React组件,其背景颜色取决于传入的道具。例如,当舞台为“内部”时,我使用color-primary-light-10类设置背景色

我正在使用React测试库和Jest Dom测试是否应用了正确的颜色:

it("should render internal stage using light primary color", () => {
    const {getByTestId} = render(<Background stage={"Internal"} />);
    expect(getByTestId(/background/i)).toHaveClass("color-primary-light-10");
});
我试着阅读Jest Dom文档中的部分,但我不知道如何测试它


如何测试在使用SCSS模块时是否应用了正确的类?

您可以尝试将
样式.module.SCSS
直接导入测试文件,然后将所需的类名直接传递到
中。当您将类名传递到组件时,您可以尝试导入
style.module.scss
直接传递到测试文件,然后将所需的类名直接传递到
中。toHaveClass
的功能与传递到组件时的功能相同
Expected the element to have class:
  color-primary-light-10
Received:
  stage Background-module-scss__background___3TL4w Background-module-scss__color-primary-light-10___3CLwc