Skip to content

Commit

Permalink
fix: .contains() properly respects multiple incoming subjects (run ci) (
Browse files Browse the repository at this point in the history
  • Loading branch information
Blue F authored Dec 7, 2022
1 parent 7565282 commit 0e457b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions packages/driver/cypress/e2e/commands/querying/querying.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,11 @@ describe('src/cy/commands/querying', () => {
})
})

// https://github.com/cypress-io/cypress/issues/25025
it('searches multiple subject elements', () => {
cy.get('ul').contains('li', 'asdf 3')
})

it('resets the subject between chain invocations', () => {
const span = cy.$$('.k-in:contains(Quality Control):last')
const label = cy.$$('#complex-contains label')
Expand All @@ -1005,15 +1010,13 @@ describe('src/cy/commands/querying', () => {

cy.get('#click-me a').contains('click').then(($span) => {
expect($span.length).to.eq(1)

expect($span.get(0)).to.eq(span.get(0))
})
})

it('can find input type=submits by value', () => {
cy.contains('input contains submit').then(($el) => {
expect($el.length).to.eq(1)

expect($el).to.match('input[type=submit]')
})
})
Expand All @@ -1022,15 +1025,13 @@ describe('src/cy/commands/querying', () => {
it('can find input type=submits by Regex', () => {
cy.contains(/input contains submit/).then(($el) => {
expect($el.length).to.eq(1)

expect($el).to.match('input[type=submit]')
})
})

it('has an optional filter argument', () => {
cy.contains('ul', 'li 0').then(($el) => {
expect($el.length).to.eq(1)

expect($el).to.match('ul')
})
})
Expand All @@ -1046,7 +1047,6 @@ describe('src/cy/commands/querying', () => {
it('searches all els in comma separated filter', () => {
cy.contains('a,button', 'Naruto').then(($el) => {
expect($el.length).to.eq(1)

expect($el).to.match('a')
})

Expand Down
16 changes: 9 additions & 7 deletions packages/driver/src/cy/commands/querying/querying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,19 @@ export default (Commands, Cypress, cy, state) => {
subject = cy.getSubjectFromChain(withinSubject || [cy.$$('body')])
}

getOptions.withinSubject = subject[0] ?? subject
let $el = getFn()
let $el = cy.$$()

// .get() looks for elements *inside* the current subject, while contains() wants to also match the current
// subject itself if no child matches.
if (!$el.length) {
$el = (subject as JQuery).filter(selector)
}
subject.each((index, element) => {
getOptions.withinSubject = element
$el = $el.add(getFn())
})

if ($el.length) {
$el = $dom.getFirstDeepestElement($el)
} else {
// .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)
}

log && cy.state('current') === this && log.set({
Expand Down

5 comments on commit 0e457b8

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0e457b8 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-0e457b8235458bde22bb5eb0118a2cca259f85f1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0e457b8 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-0e457b8235458bde22bb5eb0118a2cca259f85f1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0e457b8 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-0e457b8235458bde22bb5eb0118a2cca259f85f1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0e457b8 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-0e457b8235458bde22bb5eb0118a2cca259f85f1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0e457b8 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-0e457b8235458bde22bb5eb0118a2cca259f85f1/cypress.tgz

Please sign in to comment.