mardi 23 mars 2021

React Component Testing with Cypress - Where does 'type' come from?

Trying to do some Cypress component (react). Looking at the src for Cypress itself (node_modules/@cypress/react/dist/mount.js), the mount function takes two params:

mount(jsx, options)

When I debug my test, jsx is an object of type Symbol(react.element), with an attribute of type which is undefined, but is then passed in to a further function, getDisplayName(type), which looks for type.displayName - producing an error of 'Cannot read property 'displayName' of undefined'.

I've tried a few versions of Cypress 6.x, with @cypress/React at 4.16.4.

As per the docs for Cypress, my call to mount looks like:

const myProps = {
  blah: 'something',
  bloop: 'something else'
}

mount(<myComponent {...myProps} />);

Can anyone suggest what is wrong? How / why would my jsx param in the call to 'mount' have a type attribute? Should that come from the component definition? FWIW, component being tested is .js, not .jsx, if that matters?

TIA

Aucun commentaire:

Enregistrer un commentaire