javascripttypescriptjestjscypresschai

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. I have my jest test that run ok and everything is fine with that, then I installed cypress by executing this command

 yarn add cypress @cypress/react @cypress/webpack-dev-server

And I have my test in Cypress that runs ok whenever I try them using

yarn cypress open-ct

But the thing is, that Chai assertions works well in the test but show errors in my 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:

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

Changing the test assertion to this:

expect(clicked).toEqual(clicked)

shows this error:

enter image description here

I don't really care if I have to use Jest or Chai assertions as long as this works. 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.

Thanks!


Solution

  • Thank you @jonrsharpe for spending your time with this typescript newbie :)

    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'