Skip to content

Commit

Permalink
fix(angular): mount cy-root in original location (#25965)
Browse files Browse the repository at this point in the history
* fix(angular): mount cy-root in original location

* correctly fix insertRootElement to preserves html hierarchy, trim system-tests

---------

Co-authored-by: Zachary Williams <[email protected]>
  • Loading branch information
mv740 and ZachJW34 authored Mar 1, 2023
1 parent 79d0a16 commit e674f43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion npm/angular/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export class CypressTestComponentRenderer extends TestComponentRenderer {
const rootElement = getContainerEl()

rootElement.setAttribute('id', rootElId)
document.body.appendChild(rootElement)
}

override removeAllRootElements () {
Expand Down
29 changes: 29 additions & 0 deletions system-tests/project-fixtures/angular/src/app/mount.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,32 @@ describe('angular mount', () => {
cy.mount(MyClass)
})
})

context('component-index.html', () => {
before(() => {
const cyRootSelector = '[data-cy-root]'
const cyRoot = document.querySelector(cyRootSelector)!

expect(cyRoot.parentElement === document.body)
document.body.innerHTML = `
<div id="container">
<div data-cy-root></div>
</div>
`
})

it('preserves html hierarchy', () => {
const cyRootSelector = '[data-cy-root]'

cy.mount(ChildComponent, { componentProperties: { msg: 'Render 1' } })
cy.contains('Render 1')
cy.get(cyRootSelector).should('exist').parent().should('have.id', 'container')
cy.get('#container').should('exist').parent().should('have.prop', 'tagName').should('eq', 'BODY')

// structure persists after teardown
cy.mount(ChildComponent, { componentProperties: { msg: 'Render 2' } })
cy.contains('Render 2')
cy.get(cyRootSelector).should('exist').parent().should('have.id', 'container')
cy.get('#container').should('exist').parent().should('have.prop', 'tagName').should('eq', 'BODY')
})
})

0 comments on commit e674f43

Please sign in to comment.