Here is a snip of my test code:
cy.get('div[data-component-data-id=301602] h2:first')
.should(($el) => {
expect($el).to.have.text('dress')
})
and cypress complains about the assertion:
CypressError: Timed out retrying: You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a jQuery object.
The chai-jQuery assertion you used was:
> text
The invalid subject you asserted on was:
> Object{3}
To use chai-jQuery assertions your subject must be valid.
This can sometimes happen if a previous assertion changed the subject.
So I have to change expect($el).to.have.text('dress') to expect($el[0]).to.have.text('dress'), then the complain dismissed and test passed.
I debug the assertion a bit, turns out $el[0] is also a jquery element.
Here is a snapshot about $el and $el[0]:
So my question is: Isn't cy.get equivalent to jquery $? Why should I have to get the first element from $el? Why $el[0] is also a jquery element?
Thanks in advance.
EDIT:
It turns out that this error related to the application code when it includes zepto library. I have raised an issue in the Cypress Github repository which you can track the progress.
