fix: Fix querying shadow dom in cy.within (#8505)

This commit is contained in:
Chris Breiding
2020-09-04 15:00:56 -04:00
committed by GitHub
parent 8d5c75634e
commit 7706670caf
2 changed files with 34 additions and 2 deletions
@@ -357,6 +357,38 @@ describe('src/cy/commands/querying', () => {
})
})
describe('shadow dom', () => {
beforeEach(() => {
cy.visit('/fixtures/shadow-dom.html')
})
it('finds element within shadow dom with includeShadowDom option', () => {
cy.get('#parent-of-shadow-container-0').within(() => {
cy
.get('p', { includeShadowDom: true })
.should('have.length', 1)
.should('have.text', 'Shadow Content 3')
})
})
it('when within subject is shadow root, finds element without needing includeShadowDom option', () => {
cy.get('#shadow-element-1').shadow().within(() => {
cy
.get('p')
.should('have.length', 1)
.should('have.text', 'Shadow Content 1')
})
})
it('when within subject is already in shadow dom, finds element without needing includeShadowDom option', () => {
cy.get('.shadow-8-nested-1', { includeShadowDom: true }).within(() => {
cy
.get('.shadow-8-nested-5')
.should('have.text', '8')
})
})
})
describe('.log', () => {
beforeEach(function () {
this.logs = []
+2 -2
View File
@@ -282,7 +282,7 @@ module.exports = (Commands, Cypress, cy, state) => {
let scope = options.withinSubject
if (options.includeShadowDom) {
const root = options.withinSubject || cy.state('document')
const root = options.withinSubject ? options.withinSubject[0] : cy.state('document')
const elementsWithShadow = $dom.findAllShadowRoots(root)
scope = elementsWithShadow.concat(root)
@@ -536,7 +536,7 @@ module.exports = (Commands, Cypress, cy, state) => {
},
})
Commands.addAll({ prevSubject: 'element' }, {
Commands.addAll({ prevSubject: ['element', 'document'] }, {
within (subject, options, fn) {
let userOptions = options
const ctx = this