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

add "be.focused" and "have.focus" to assertions #3219

Merged
merged 19 commits into from
May 1, 2019

Conversation

kuceb
Copy link
Contributor

@kuceb kuceb commented Jan 24, 2019

fix #97 add focus assertion

I wanted this to help me write some tests, so here it is

with this PR, the following are valid 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
cy.get('.non-existent-sel').should('not.be.visible') 

will still pass as it does today. not.be.visible will continue to behave the same as not.exist

  • add type definitions
  • refactored to use jquery assertion
  • fix specs that use should not.be.visible
  • include error message about changing not.visible to not.exist
  • allow not.be.visible to pass on non-existent selectors as before
  • factor out breaking changes
  • fix bug where jquery isn't calling into custom :focus selector

docs cypress-io/cypress-documentation#1362

  • add 'have.focus' to should assertions
  • remove docs that say should('not.have.element') will pass with no DOM node

@kuceb kuceb changed the base branch from develop to v3.2.0 January 25, 2019 00:11
@kuceb kuceb changed the base branch from v3.2.0 to develop January 25, 2019 00:11
@kuceb kuceb changed the base branch from develop to v3.2.0 January 25, 2019 00:11
@kuceb kuceb changed the title add "be.focused" to chai_jquery add "be.focused" and "have.focus" to assertions Jan 25, 2019
cli/types/index.d.ts Outdated Show resolved Hide resolved
packages/driver/src/cypress/chai_jquery.coffee Outdated Show resolved Hide resolved
packages/driver/src/cypress/chai_jquery.coffee Outdated Show resolved Hide resolved
@brian-mann
Copy link
Member

If this fixes the negated assertion bug from a long time ago that would be huge!

@brian-mann
Copy link
Member

The desktop-gui tests are legit failing though: https://circleci.com/gh/cypress-io/cypress/54253

@kuceb
Copy link
Contributor Author

kuceb commented Jan 25, 2019

got it, tests were doing cy.get('non-existent-element').should('not.be.visible'), which now rightfully fails. Changed them to use should('not.exist')

@dwelle
Copy link

dwelle commented Jan 26, 2019

Good. Let's not forget to revert cypress-io/cypress-documentation#1289 when this get merged.

@kuceb
Copy link
Contributor Author

kuceb commented Jan 28, 2019

Good. Let's not forget to revert cypress-io/cypress-documentation#1289 when this get merged.

🥇 great catch @dwelle

Copy link
Member

@brian-mann brian-mann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the focus assertions and extract out the not.xyz as a separate PR for 4.0 breaking changes.

…ocus-assertion"

This reverts commit b401c32, reversing
changes made to ab14758.
@kuceb kuceb requested a review from brian-mann January 31, 2019 19:47
@jennifer-shehane jennifer-shehane requested review from a team and removed request for brian-mann and jennifer-shehane March 6, 2019 18:43
@kuceb kuceb changed the base branch from v3.2.0 to v3.3.0 March 18, 2019 19:13
@kuceb kuceb reopened this Mar 18, 2019
@kuceb kuceb requested a review from brian-mann April 30, 2019 20:02
@brian-mann brian-mann merged commit 49ec098 into v3.3.0 May 1, 2019
brian-mann added a commit that referenced this pull request May 21, 2019
* add "be.focused" to chai_jquery

* add comment explaining the mess

* add type definitions

* refactor assertion to use jquery assertion

* remove trailing whitespace

* add test for multiple elements, update typedefs

* fix failing tests: not.be.visible -> not.exist

* allow should(not.be.visible) for failed selectors

* remove unrelated visibility changes

* extract only focus assertion

* Revert "Merge remote-tracking branch 'origin/develop' into issue-97-focus-assertion"

This reverts commit b401c32, reversing
changes made to ab14758.

* force jquery to use custom focus pseudo selector

* only force custom matchers for focus selectors

* rewrote matchesSelector wrap code

* add lodash

* Merge in origin/develop

* changes on 3.3.0

Co-authored-by: Brian Mann <brian.mann86@gmail.com>
@emilyrohrbough emilyrohrbough deleted the issue-97-focus-assertion branch August 1, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants