Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't chain negative `cy.should()` with a `.find()` #3917

Kocal opened this Issue Apr 9, 2019 · 2 comments


2 participants
Copy link

Kocal commented Apr 9, 2019

Hi :)

I'm having an issue while trying to using .find() after a negative assertion on an attribute.

Current behavior:


Desired behavior:

Using cy.get('...').should('not.have.attr') should yield the current element, like cy.get('...').should('have.attr') does.


Steps to reproduce: (app code and test code)

I've created a repo that reproduce the issue.

You fill wind everything here Kocal/cypress-issue-should-not-have-attr@9947ed8


  • Cypress: 3.1.5 and 3.2.0
  • OS: Debian 9.8 (Stretch)
  • Browser: Electron 59, the one packaged with Cypress

Thanks! :)


This comment has been minimized.

Copy link

Kocal commented Apr 9, 2019

Well, in fact I don't know if it's really a bug or a requested feature, because the docs says:

In most cases, .should() yields the same subject it was given from the previous command.

However, some chainers change the subject.


But that would be really nice to chain on cy.should('not.have.attr', ...)

@Kocal Kocal changed the title Can't shain negative `cy.should()` with a `.find()` Can't chain negative `cy.should()` with a `.find()` Apr 9, 2019


This comment has been minimized.

Copy link

jennifer-shehane commented Apr 9, 2019

Yeah, I think the difference is the use of 3 arguments versus 2 arguments.

 // works
.should('have.attr', 'data-sorted', 'desc') 
 // doesn't work
.should('not.have.attr', 'data-sorted') 

This second example changes the subject to the 'data-sorted' attribute, because you can usually further chain.

 // works
.should('have.attr', 'data-sorted').and.match('/desc/)

I think the fact that the first example with 3 arguments is a bit weird that it returns the DOM element, but this comes directly from Chai jQuery's implementation.

We will not be changing this implementation at this time, so will close this issue. We may reconsider reopening depending on the amount of feedback wanting this feature in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.