我正在使用反应测试库和笑话来测试我的反应应用程序。
我想知道如何在react-testing-library中获取具有“name”属性的元素。
例如,在下面的页面中,是否可以通过“userName”获取此元素?
<input type="text" name="userName" />
Run Code Online (Sandbox Code Playgroud)
或者我应该设置data-testId到元素并使用getByTestId方法?
return (
<div>
<input type="text" name="userName" />
</div>
)
Run Code Online (Sandbox Code Playgroud) 我正在构建由 create-react-app 提供的 React 应用程序。
\n我使用 craco 来简化配置,并为 TypeScript 和 Webpack 设置了 alise。
\n但是当我运行测试命令时,显示以下错误。
\n spec/showMessage.test.tsx\n \xe2\x97\x8f Test suite failed to run\n\n Cannot find module '@/components/atom/TextButton' from 'src/pages/index.tsx'\n\n Require stack:\n src/pages/index.tsx\n spec/showMessage.test.tsx\n\n 3 | import styled from 'styled-components';\n 4 | \n > 5 | import { TextButton } from '@/components/atom/TextButton';\n | ^\n\nRun Code Online (Sandbox Code Playgroud)\n这是我的 craco.config.js
\nconst path = require("path");\n\nmodule.exports = {\n jest: {\n configure: {\n roots: ['<rootDir>/src', '<rootDir>/spec'],\n testMatch: …Run Code Online (Sandbox Code Playgroud)