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

* 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 b401c32a61, reversing
changes made to ab14758d31.

* 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>
This commit is contained in:
Ben Kucera
2019-05-21 18:56:15 -04:00
committed by Brian Mann
parent cacd122c67
commit ef5c38d178
8 changed files with 220 additions and 17 deletions
+32
View File
@@ -3593,6 +3593,22 @@ declare namespace Cypress {
* @see https://on.cypress.io/assertions
*/
(chainer: 'contain', value: string): Chainable<Subject>
/**
* Assert that at least one element of the selection is focused.
* @example
* cy.get('#result').should('have.focus')
* cy.get('#result').should('be.focused')
* @see https://on.cypress.io/assertions
*/
(chainer: 'have.focus'): Chainable<Subject>
/**
* Assert that at least one element of the selection is focused.
* @example
* cy.get('#result').should('be.focused')
* cy.get('#result').should('have.focus')
* @see https://on.cypress.io/assertions
*/
(chainer: 'be.focused'): Chainable<Subject>
/**
* Assert that the selection is not empty. Note that this overrides the built-in chai assertion. If the object asserted against is not a jQuery object, the original implementation will be called.
* @example
@@ -3749,6 +3765,22 @@ declare namespace Cypress {
* @see https://on.cypress.io/assertions
*/
(chainer: 'not.be.visible'): Chainable<Subject>
/**
* Assert that no element of the selection is focused.
* @example
* cy.get('#result').should('not.have.focus')
* cy.get('#result').should('not.be.focused')
* @see https://on.cypress.io/assertions
*/
(chainer: 'not.have.focus'): Chainable<Subject>
/**
* Assert that no element of the selection is focused.
* @example
* cy.get('#result').should('not.be.focused')
* cy.get('#result').should('not.have.focus')
* @see https://on.cypress.io/assertions
*/
(chainer: 'not.be.focused'): Chainable<Subject>
/**
* Assert that the selection does not contain the given text, using `:contains()`. If the object asserted against is not a jQuery object, or if `contain` is not called as a function, the original implementation will be called.
* @example
+6
View File
@@ -329,6 +329,12 @@ cy.get('#result').should('be.selected')
cy.get('#result').should('be.visible')
cy.get('#result').should('be.focused')
cy.get('#result').should('not.be.focused')
cy.get('#result').should('have.focus')
cy.get('#result').should('not.have.focus')
cy.get('#result').should('be.contain', 'text')
cy.get('#result').should('have.attr', 'role')