我之前一直在使用react-testing-library
以及@testing-library/jest-dom/extend-expect
。昨天我安装了Cypress,现在所有的jest匹配器都出现Typescript错误:
Property 'toEqual' doesn't exist on type 'Assertion'. Did you mean 'equal'?
似乎是从错误的断言库获取了expect
的类型?此外,expect(...).to.equal(...)
也无法工作。
我尝试安装了@types/jest
,看起来yarn已经成功了,但它没有列在我的package.json
的devDependencies
中。
以下是我的tsconfig
:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"noImplicitAny": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"noEmit": true,
"jsx": "react",
"skipDefaultLibCheck": true,
"types": [
"node",
"cypress",
"jest"
]
},
"include": [
"src"
]
}
我还要提到,我的所有Cypress测试中的cy
调用都会收到来自ESLint的cy未定义
错误。
./cypress.config.ts
。建议首先尝试Marcus Fonseca的答案。 - Michael Freidgeim