Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 222b6c2

Browse files
committed
fix: cypress-jsdom -> cypress-root
1 parent 9d49151 commit 222b6c2

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

cypress/component/advanced/react-book-example/src/Todos.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ it('Todo - should create snapshot', () => {
2222
// expect(tree).toMatchSnapshot();
2323

2424
// entire test area
25-
cy.get('#cypress-jsdom')
25+
cy.get('#cypress-root')
2626
.invoke('html')
2727
.then(pretty)
2828
.should(

cypress/component/advanced/renderless/mouse-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Renderless component', () => {
1414
})
1515
const onMoved = cy.stub()
1616
mount(<MouseMovement onMoved={onMoved} />)
17-
cy.get('#cypress-jsdom').should('be.empty')
17+
cy.get('#cypress-root').should('be.empty')
1818
cy.document()
1919
.trigger('mousemove')
2020
.then(() => {

cypress/component/advanced/set-timeout-example/loading-indicator-spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ describe('LoadingIndicator', () => {
6969
</LoadingIndicator>,
7070
)
7171
cy.tick(2010)
72-
cy.get('#cypress-jsdom').then($el => {
72+
cy.get('#cypress-root').then($el => {
7373
unmountComponentAtNode($el[0])
7474
})
7575
cy.get('@clearTimeout').should('have.been.calledOnce')
7676
})
7777
})
7878

7979
afterEach(() => {
80-
cy.get('#cypress-jsdom').then($el => {
80+
cy.get('#cypress-root').then($el => {
8181
unmountComponentAtNode($el[0])
8282
})
8383
})

cypress/component/advanced/timers/card-without-effect-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ it('should cleanup on being removed', () => {
2424
expect(onSelect).to.not.have.been.called
2525
})
2626

27-
cy.get('#cypress-jsdom').then($el => {
27+
cy.get('#cypress-root').then($el => {
2828
unmountComponentAtNode($el[0])
2929
})
3030

cypress/component/basic/react-tutorial/pretty-snapshots-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import pretty from 'pretty'
77
it('says hello world', () => {
88
mount(<Hello name="world" />)
99
cy.contains('Hello, world!').should('be.visible')
10-
cy.get('#cypress-jsdom')
10+
cy.get('#cypress-root')
1111
.invoke('html')
1212
.then(pretty)
1313
.should('equal', '<h1>Hello, world!</h1>')

lib/hooks.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
/** Initialize an empty document with root element */
22
function renderTestingPlatform() {
3+
// Let's mount components under a new div with this id
4+
const rootId = 'cypress-root'
5+
36
const document = cy.state('document') as Document
4-
if (document.getElementById('cypress-jsdom')) {
7+
if (document.getElementById(rootId)) {
58
return
69
}
710

811
const rootNode = document.createElement('div')
9-
rootNode.setAttribute('id', 'cypress-jsdom')
12+
rootNode.setAttribute('id', rootId)
1013
document.getElementsByTagName('body')[0].prepend(rootNode)
1114

12-
return cy.get('#cypress-jsdom', { log: false })
15+
const selector = '#' + rootId
16+
return cy.get(selector, { log: false })
1317
}
1418

1519
before(() => {

lib/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import ReactDOM, { unmountComponentAtNode } from 'react-dom'
33
import getDisplayName from './getDisplayName'
44
import { injectStylesBeforeElement } from './utils'
55

6+
const rootId = 'cypress-root'
7+
68
function checkMountModeEnabled() {
79
// @ts-ignore
810
if (Cypress.spec.specType !== 'component') {
@@ -17,7 +19,7 @@ function checkMountModeEnabled() {
1719
*/
1820
const injectStyles = (options: MountOptions) => () => {
1921
const document = cy.state('document')
20-
const el = document.getElementById('cypress-jsdom')
22+
const el = document.getElementById(rootId)
2123
return injectStylesBeforeElement(options, document, el)
2224
}
2325

@@ -65,7 +67,7 @@ export const mount = (jsx: React.ReactElement, options: MountOptions = {}) => {
6567
const document = cy.state('document')
6668
const reactDomToUse = options.ReactDom || ReactDOM
6769

68-
const el = document.getElementById('cypress-jsdom')
70+
const el = document.getElementById(rootId)
6971

7072
const props = {
7173
// @ts-ignore provide unique key to the the wrapped component to make sure we are rerendering between tests
@@ -90,7 +92,8 @@ export const unmount = () => {
9092
checkMountModeEnabled()
9193

9294
cy.log('unmounting...')
93-
return cy.get('#cypress-jsdom', { log: false }).then($el => {
95+
const selector = '#' + rootId
96+
return cy.get(selector, { log: false }).then($el => {
9497
unmountComponentAtNode($el[0])
9598
})
9699
}

0 commit comments

Comments
 (0)