首页 > 解决方案 > 如何在 setup.test.js 中结合酶和反应测试库的配置

问题描述

我们的项目同时具有enzymetesting-library。我的目标是将getByTestId覆盖到我的自定义中。但是,当我将第二个配置添加到我的 setup.test.js 时,一些测试会因Found multiple elements with the text.

setup.test.js:

const { configure } = require("enzyme");
const Adapter = require("enzyme-adapter-react-16");
import { configure as conf } from "@testing-library/react";

window.__config = {};
conf({ testIdAttribute: "data-my-test-id" });
configure({ adapter: new Adapter() });

我的版本:

“酶”:“^3.11.0”,

"@testing-library/react": "^11.0.4",

标签: react-testing-librarytesting-library

解决方案


推荐阅读