So I know that Cypress have a vendeta out on Conditional Testing but there are cases where it is necessary and worth the risk of flakiness (actually it can reduce flakiness even for a well designed test).
One that I run into a lot is when using visual regression testing such as Percy. Visual regression takes a snapshot so of course it is the programmers responsibility to ensure that the DOM is stable. There is no other choice. The buit in Cypress commands as well as the Testing Library ones makes this pretty easy to do. Once it is stable we can use queries to modify the DOM, such as setting all dates to a known value, and then finally take the snapshot.
Would you consider bringing back the queryBy... APIs?
It is not sufficient to do findBy().should('not.exist') as sometimes we reusable logic that will work whether the elements exist or not.
For the snapshot case I want a single snapshot function which I can call on any page of my app in any state which knows how to replace dates, times, randomly generated emails etc. whether they are present or not. Without this, I have write a custom snapshot function for every single test which is horrible.
The technique used in cypress-if is a pretty good approach.
So I know that Cypress have a vendeta out on Conditional Testing but there are cases where it is necessary and worth the risk of flakiness (actually it can reduce flakiness even for a well designed test).
One that I run into a lot is when using visual regression testing such as Percy. Visual regression takes a snapshot so of course it is the programmers responsibility to ensure that the DOM is stable. There is no other choice. The buit in Cypress commands as well as the Testing Library ones makes this pretty easy to do. Once it is stable we can use queries to modify the DOM, such as setting all dates to a known value, and then finally take the snapshot.
Would you consider bringing back the
queryBy...
APIs?It is not sufficient to do
findBy().should('not.exist')
as sometimes we reusable logic that will work whether the elements exist or not.For the snapshot case I want a single snapshot function which I can call on any page of my app in any state which knows how to replace dates, times, randomly generated emails etc. whether they are present or not. Without this, I have write a custom snapshot function for every single test which is horrible.
The technique used in cypress-if is a pretty good approach.