forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow-spec.js
35 lines (30 loc) · 833 Bytes
/
window-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
export class Component extends React.Component {
constructor(props) {
super(props)
console.log(
'set window.counter to this component in window',
window.location.pathname,
)
window.component = this
}
render() {
return <p>component</p>
}
}
it('has the same window from the component as from test', () => {
cy.window()
.its('location')
.should('have.property', 'pathname')
.and('not.equal', 'blank')
mount(<Component />)
cy.contains('component')
cy.window()
.its('location.pathname')
// this filename
.should('match', /window-spec\.js$/)
// the window should have property set by the component
cy.window().should('have.property', 'component')
})