Skip to content

Commit

Permalink
fix: .contains() should only return one element at all times (#25250)
Browse files Browse the repository at this point in the history
* fix: .contains() should only return one element at all times

* Improve test name

* Add additional test
  • Loading branch information
Blue F authored Jan 3, 2023
1 parent acc61d8 commit 05b9f10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/driver/cypress/e2e/commands/querying/querying.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,15 @@ describe('src/cy/commands/querying', () => {
})
})

// https://github.com/cypress-io/cypress/issues/25225
it('returns only one element when given multiple subjects directly match selector', () => {
// A case with only a text selector
cy.get('button').contains('submit').should('have.length', 1)

// A case with a filter + text selector
cy.get('div').contains('div', 'foo').should('have.length', 1)
})

// https://github.com/cypress-io/cypress/issues/25019
it('can locate elements contained inside <form> containers', () => {
cy.get('#focus').contains('button', 'focusable')
Expand Down
6 changes: 3 additions & 3 deletions packages/driver/src/cy/commands/querying/querying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ export default (Commands, Cypress, cy, state) => {
$el = $el.add(getFn())
})

if ($el.length) {
$el = $dom.getFirstDeepestElement($el)
} else {
if (!$el.length) {
// .get() looks for elements *inside* the current subject, while contains() wants to also match the current
// subject itself if no child matches.
$el = (subject as JQuery).filter(selector)
}

$el = $dom.getFirstDeepestElement($el)

log && cy.state('current') === this && log.set({
$el,
consoleProps: () => {
Expand Down

5 comments on commit 05b9f10

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05b9f10 Jan 3, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/linux-arm64/develop-05b9f101201e4e7b2a6bbeba39f2fdeff5fc89d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05b9f10 Jan 3, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/linux-x64/develop-05b9f101201e4e7b2a6bbeba39f2fdeff5fc89d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05b9f10 Jan 3, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/darwin-arm64/develop-05b9f101201e4e7b2a6bbeba39f2fdeff5fc89d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05b9f10 Jan 3, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/darwin-x64/develop-05b9f101201e4e7b2a6bbeba39f2fdeff5fc89d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 05b9f10 Jan 3, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/win32-x64/develop-05b9f101201e4e7b2a6bbeba39f2fdeff5fc89d7/cypress.tgz

Please sign in to comment.