cypress-io / cypress-documentation

Cypress Documentation including Guides, API, Plugins, Examples, & FAQ.

Home Page:https://docs.cypress.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why is cy.should() doc uses examples with magic strings instead of using typed function expect expressions?

LazaroOnline opened this issue · comments

Subject

API Commands should

Description

In cypress documentation, particularly in the should command docs it shows many examples using "magic strings" like this .should('be.visible')
instead of using typed functions like .should($el => expect($el).to.be.visible()).

If it is for having a shorter method maybe we could have something like this: .expect((to) => to.be.visible()) and keep the typing, but it is still not as short as the original string version.
The problem with strings is that you don't know during build with typescript if the assertion is correct, and during development there are no automatic suggestions for strings.

If there was already a typed way of doing assertions that is closer to the subjacent Chai framework, why did Cypress created the other methods using strings? just because it takes some less characters to write?
Or is there any benefit using the magic string variant or are they exactly the same?

@LazaroOnline Not all of our users use typescript, so it's offering examples in a generic way for any javascript users. We recommend you use the approach that works best for your project.