Skip to content

Commit e674f43

Browse files
mv740ZachJW34
andauthored
fix(angular): mount cy-root in original location (#25965)
* fix(angular): mount cy-root in original location * correctly fix insertRootElement to preserves html hierarchy, trim system-tests --------- Co-authored-by: Zachary Williams <ZachJW34@gmail.com>
1 parent 79d0a16 commit e674f43

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

npm/angular/src/mount.ts

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ export class CypressTestComponentRenderer extends TestComponentRenderer {
179179
const rootElement = getContainerEl()
180180

181181
rootElement.setAttribute('id', rootElId)
182-
document.body.appendChild(rootElement)
183182
}
184183

185184
override removeAllRootElements () {

system-tests/project-fixtures/angular/src/app/mount.cy.ts

+29
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,32 @@ describe('angular mount', () => {
475475
cy.mount(MyClass)
476476
})
477477
})
478+
479+
context('component-index.html', () => {
480+
before(() => {
481+
const cyRootSelector = '[data-cy-root]'
482+
const cyRoot = document.querySelector(cyRootSelector)!
483+
484+
expect(cyRoot.parentElement === document.body)
485+
document.body.innerHTML = `
486+
<div id="container">
487+
<div data-cy-root></div>
488+
</div>
489+
`
490+
})
491+
492+
it('preserves html hierarchy', () => {
493+
const cyRootSelector = '[data-cy-root]'
494+
495+
cy.mount(ChildComponent, { componentProperties: { msg: 'Render 1' } })
496+
cy.contains('Render 1')
497+
cy.get(cyRootSelector).should('exist').parent().should('have.id', 'container')
498+
cy.get('#container').should('exist').parent().should('have.prop', 'tagName').should('eq', 'BODY')
499+
500+
// structure persists after teardown
501+
cy.mount(ChildComponent, { componentProperties: { msg: 'Render 2' } })
502+
cy.contains('Render 2')
503+
cy.get(cyRootSelector).should('exist').parent().should('have.id', 'container')
504+
cy.get('#container').should('exist').parent().should('have.prop', 'tagName').should('eq', 'BODY')
505+
})
506+
})

0 commit comments

Comments
 (0)