import '@testing-library/jest-dom/extend-expect';
expect(screen.getByText('User does not exist.')).toBeInTheDocument()
Run Code Online (Sandbox Code Playgroud)
我正在为我的网络应用程序编写单元测试,我在代码中使用 toBeInTheDocument() ,但是在终端中运行 npm test 后,它显示“找不到模块”@testing-library/jest-dom/extend-expect '来自'jest.setup.js''。
我有一个 jest.setup.js 文件,其中包含代码:require('@testing-library/jest-dom/extend-expect');
还有一个 jest.config.js 文件,其中包含代码: setupFilesAfterEnv:["./jest.setup.js"],
我还导入 '@testing-library/jest-dom/extend-expect'; 在我的 test.tsx 文件中,还要检查 node_modules 下是否有 @testing-library/jest-dom 。我现在该怎么办?
Dav*_*ley 30
这是6.0 版本中的一项重大更改,删除了扩展期望入口点,转而采用默认入口点和一些特定于平台的入口点。对于我的用例,默认入口点有效:
import '@testing-library/jest-dom'
Run Code Online (Sandbox Code Playgroud)