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

Commit 083ab73

Browse files
committed
fix: guard hooks to run only for component specs, closes #180
1 parent 7d8c9fc commit 083ab73

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
/// <reference types="cypress" />
2-
it('loads page for E2E', () => {
3-
cy.visit('index.html')
4-
cy.window().should('have.property', 'React')
2+
describe('integration tests', () => {
3+
it('loads page for E2E', () => {
4+
cy.visit('index.html')
5+
cy.window().should('have.property', 'React')
6+
})
7+
8+
it('loads page again', () => {
9+
cy.visit('index.html')
10+
cy.window().should('have.property', 'React')
11+
})
512
})

lib/hooks.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// @ts-ignore
2+
const isComponentSpec = () => Cypress.spec.specType === 'component'
3+
14
/** Initialize an empty document with root element */
25
function renderTestingPlatform() {
36
// Let's mount components under a new div with this id
@@ -17,6 +20,10 @@ function renderTestingPlatform() {
1720
}
1821

1922
before(() => {
23+
if (!isComponentSpec()) {
24+
return
25+
}
26+
2027
renderTestingPlatform()
2128
})
2229

@@ -26,6 +33,9 @@ before(() => {
2633
*
2734
*/
2835
function cleanupStyles() {
36+
if (!isComponentSpec()) {
37+
return
38+
}
2939
const document = cy.state('document') as Document
3040

3141
const styles = document.body.querySelectorAll('style')

lib/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { injectStylesBeforeElement } from './utils'
55

66
const rootId = 'cypress-root'
77

8+
// @ts-ignore
9+
const isComponentSpec = () => Cypress.spec.specType === 'component'
10+
811
function checkMountModeEnabled() {
912
// @ts-ignore
10-
if (Cypress.spec.specType !== 'component') {
13+
if (!isComponentSpec()) {
1114
throw new Error(
1215
`In order to use mount or unmount functions please place the spec in component folder`,
1316
)

0 commit comments

Comments
 (0)