Skip to content

Commit

Permalink
fix: .contains() selects proper elements when inside a <form> (#25038)
Browse files Browse the repository at this point in the history
* fix: .contains() selects proper elements when inside a <form>

* Fix withinSubject to always be jquery object, and always pass a dom element to findAllShadowRoots

* Typo in last commit
  • Loading branch information
Blue F authored Dec 7, 2022
1 parent 0e457b8 commit 79f743e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/driver/cypress/e2e/commands/querying/querying.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,11 @@ describe('src/cy/commands/querying', () => {
})
})

// https://github.com/cypress-io/cypress/issues/25019
it('can locate elements contained inside <form> containers', () => {
cy.get('#focus').contains('button', 'focusable')
})

it('can find input type=submits by value', () => {
cy.contains('input contains submit').then(($el) => {
expect($el.length).to.eq(1)
Expand Down
8 changes: 2 additions & 6 deletions packages/driver/src/cy/commands/querying/querying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,8 @@ export default (Commands, Cypress, cy, state) => {
try {
let scope = userOptions.withinSubject || cy.getSubjectFromChain(withinSubject)

if (scope && scope[0]) {
scope = scope[0]
}

if (includeShadowDom) {
const root = scope || cy.state('document')
const root = scope?.get(0) || cy.state('document')
const elementsWithShadow = $dom.findAllShadowRoots(root)

scope = elementsWithShadow.concat(root)
Expand Down Expand Up @@ -327,7 +323,7 @@ export default (Commands, Cypress, cy, state) => {
let $el = cy.$$()

subject.each((index, element) => {
getOptions.withinSubject = element
getOptions.withinSubject = cy.$$(element)
$el = $el.add(getFn())
})

Expand Down

5 comments on commit 79f743e

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 79f743e Dec 7, 2022

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.2/linux-arm64/develop-79f743e1cfaec7f3938a68a5074f1bfe1ab22b87/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 79f743e Dec 7, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.2/linux-x64/develop-79f743e1cfaec7f3938a68a5074f1bfe1ab22b87/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 79f743e Dec 7, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.2/darwin-arm64/develop-79f743e1cfaec7f3938a68a5074f1bfe1ab22b87/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 79f743e Dec 7, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.2/darwin-x64/develop-79f743e1cfaec7f3938a68a5074f1bfe1ab22b87/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 79f743e Dec 7, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.2/win32-x64/develop-79f743e1cfaec7f3938a68a5074f1bfe1ab22b87/cypress.tgz

Please sign in to comment.