abhinaba-ghosh / cypress-react-selector

:zap: cypress plugin to locate react elements by component, props and state
https://www.cypress.io/
MIT License
274 stars 28 forks source link

How to call the function inside of a component? #428

Open vikasm98 opened 1 year ago

vikasm98 commented 1 year ago

I am getting the component when I use

cy.getReact('BasicTray').then((comp) => {
      cy.log('comp', comp)
})

and in the logs I can see the following output as shown in the image

Screenshot 2023-05-17 at 8 48 26 PM

but I am not able to get the function exists inside of that component. I use this code to get the function of that component cy.getReact('BasicTray').invoke('toggleMic')

I am getting this fllowing error

Screenshot 2023-05-17 at 8 52 24 PM

i am also getting the same error when i want to get the variable inside of that component is there a way to get the function and call the function inside cypress end to end testing?

FDiskas commented 11 months ago

This is similar you would ask - how users by visiting a website could invoke some random react component function visible on the page.

Looks like you need to take a look at unit tests instead of e2e. E2E tests should test users' flow and interactions.