[英]Property does not exist on type 'JestMatchers '
I'm working with an app where I want to have installed jest and cypress for testing purposes.我正在使用一个应用程序,我想在其中安装 jest 和 cypress 以进行测试。 I have my jest test that run ok and everything is fine with that, then I installed cypress by executing this command
我的 jest 测试运行正常,一切都很好,然后我通过执行此命令安装了 cypress
yarn add cypress @cypress/react @cypress/webpack-dev-server
And I have my test in Cypress that runs ok whenever I try them using而且我在 Cypress 中进行了测试,每当我尝试使用它们时,它都可以正常运行
yarn cypress open-ct
But the thing is, that Chai assertions works well in the test but show errors in my IDE但问题是,Chai 断言在测试中运行良好,但在我的 IDE 中显示错误
My dummy test我的假人测试
it('Test test and onClick', () => {
let clicked = false
const onClick = () => (clicked = true)
mount(<Button text="Random text" onClick={onClick} />)
cy.get('button').should('have.text', 'Random text')
cy.get('button')
.click()
.then(() => {
expect(clicked).to.equal(clicked)
})
})
and the error shown:并显示错误:
I have tried to follow some guides I saw on the Internet but I'm missing something because my IDE (Webstorm or Visual Studio) only suggests me Jest assertions not Chai's, and if I use Jest assertion I got this error while running Cypress我试图遵循我在互联网上看到的一些指南,但我遗漏了一些东西,因为我的 IDE(Webstorm 或 Visual Studio)只向我建议 Jest 断言而不是 Chai 的,如果我使用 Jest 断言,我在运行 Cypress 时遇到了这个错误
Changing the test assertion to this:将测试断言更改为:
expect(clicked).toEqual(clicked)
shows this error:显示此错误:
I don't really care if I have to use Jest or Chai assertions as long as this works.我真的不在乎我是否必须使用 Jest 或 Chai 断言,只要它有效。 My preference will be Chai's because are the ones that works within Cypress, but right now, I only wanted that to don't show an error in my IDE or in Cypress.
我更喜欢 Chai 的,因为它们可以在 Cypress 中运行,但现在,我只希望它不会在我的 IDE 或 Cypress 中显示错误。
Thanks!谢谢!
Thank you @jonrsharpe for spending your time with this typescript newbie :)谢谢@jonrsharpe 花时间在这个打字稿新手上:)
I have fixed it by installing chai and mocha dependencies with yarn add --dev chai mocha ts-node @types/chai @types/mocha
and adding this to my cypress test file import { expect } from 'chai'
我已经通过使用
yarn add --dev chai mocha ts-node @types/chai @types/mocha
安装 chai 和 mocha 依赖项来修复它,并将其添加到我的 cypress 测试文件import { expect } from 'chai'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.