question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for "focus" assertion (to work effectively as Chai jQuery assertion does)

See original GitHub issue

Chai jQuery added a focus assertion recently.

Cypress needs support for focus assertions so I can assert whether a DOM element has or does not have focus.

Example

cy
  .get('input')
    .type('Foo').should('have.focus')
    .blur().should('not.have.focus')

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:26
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
kucebcommented, Jan 24, 2019

Hi, after this PR #3219 , you will be able to do the following assertions:

cy.get('div').should('have.focus')
cy.get('div').should('not.have.focus')
cy.get('div').should('be.focused')
cy.get('div').should('not.be.focused')

expect(div).to.have.focus
expect(div).to.not.have.focus
expect(div).to.be.focused
expect(div).to.not.be.focused

3reactions
kucebcommented, May 21, 2019

I’m getting “CypressError: The chainer: ‘focus’ was not found. Could not build assertion.” with Cypress 3.3.0 when I do cy.get('search_input').should('have.focus'). Am I using it wrong or should I create a new issue?

Currently looking into this

Edit: looks like it never made it into the develop branch https://github.com/cypress-io/cypress/compare/v3.3.0

We’ll have this fixed soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chai-jQuery - Chai Assertion Library
chai -jquery is an extension to the chai assertion library that provides a set of jQuery-specific assertions. Usage. Include chai-jquery.js in your test...
Read more >
Assertions | Cypress Documentation
Adding New Assertions​​ Cypress will "just work" with new assertions added to chai . You can: Write your own chai assertions as documented...
Read more >
#14 Mocha - DOM Assertion using Chai-jQuery - YouTube
When writing integration tests, you will likely work a lot with the DOM. chai - jquery is an extension to the chai assertion...
Read more >
attempted to make a chai-jQuery assertion on an object that is ...
To use chai-jQuery assertions your subject must be valid. This can sometimes happen if a previous assertion changed the subject.
Read more >
chai-dom: Docs, Community, Tutorials, Reviews | Openbase
chai -dom is an extension to the chai assertion library that provides a set of ... Forked from chai-jquery to use for those...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found