forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare-spec.js
52 lines (47 loc) · 1.2 KB
/
square-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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
// let's put React component right in the spec file
class Square extends React.Component {
constructor(props) {
super(props)
this.state = {
value: null,
}
}
render() {
return (
<button
className="square"
onClick={() => this.setState({ value: this.props.value })}
>
{this.state.value}
</button>
)
}
}
describe('Square', () => {
it.only('changes value on click', () => {
const selector = 'button.square'
mount(<Square value="X" />)
// initially button is blank
cy.get(selector).should('have.text', '')
// but it changes text on click
cy.get(selector)
.click()
.should('have.text', 'X')
})
it('looks good', () => {
mount(<Square />, {
cssFile: 'cypress/component/advanced/tutorial/tic-tac-toe.css',
})
// pause to show it
cy.wait(1000)
cy.get('.square').click()
cy.wait(1000)
// check if style was applied
cy.get('.square')
.should('have.css', 'background-color', 'rgb(255, 255, 255)')
.and('have.css', 'border', '1px solid rgb(153, 153, 153)')
})
})