我们的项目同时有enzyme
和testing-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";,
"测试库/反应":"11.0.4〃;,
发生这种情况是因为预期的清理不起作用。将下面的配置移到一个新文件中,比如说"js";
import { configure as conf } from "@testing-library/react";
conf({ testIdAttribute: "data-my-test-id" });
现在,开玩笑地.config.js:
{
setupFilesAfterEnv: ['<existing_setup_file_path>', '<path>/env-setup.js']
}