anton-kravchenko / cypress-selectors

cypress-selectors is a library that provides a bunch of convenient declarative selectors for Cypress.
MIT License
13 stars 1 forks source link

Using selector in unit tests #30

Open jonathanantoine opened 2 years ago

jonathanantoine commented 2 years ago

Hello,

I would like my development team to create the selectors to be used by my QA teams while writing their own separated cypress tests. Is there a way to use the created cypress-selectors in the unit tests ?

Thanks !

anton-kravchenko commented 2 years ago

Hello @jonathanantoine.

If you're referring to component testing then yes, you can use the selectors precisely the same way.

The package itself is essentially a collection of decorators that translate a "selector" into a chain of cy.get calls and therefore no matter what kind of test you're running (e2e or component), as long as cy.get is in scope the selectors will work.

jonathanantoine commented 2 years ago

Than you for your reply. I meant unit testing with karma (example : https://angular.io/guide/testing).

I would need to be able to retrieve the element from the Selector object.

anton-kravchenko commented 2 years ago

@jonathanantoine since this is a cypress-specific package, it's going to work only in Cypress tests. However, what you're aiming for can be done with cypress-angular-unit-test. With Cypress, it is possible to render a React/Angular/ component and test it in isolation (e.g. unit test it) right in a browser. This is also possible to configure Cypress to run tests in a headless browser in CI.