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

Commit 237ff76

Browse files
committed
add react tutorial specs
1 parent dde0331 commit 237ff76

File tree

11 files changed

+139
-0
lines changed

11 files changed

+139
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Examples from https://reactjs.org/tutorial/tutorial.html
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference types="cypress" />
2+
import ShoppingList from './shopping-list.jsx'
3+
import React from 'react'
4+
import { mount } from 'cypress-react-unit-tests'
5+
6+
describe('Shopping list', () => {
7+
beforeEach(() => {
8+
cy.viewport(600, 400)
9+
})
10+
it('renders', () => {
11+
mount(<ShoppingList name="Mark" />)
12+
cy.contains('h1', 'Mark')
13+
})
14+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
export default class ShoppingList extends React.Component {
3+
render() {
4+
return (
5+
<div className="shopping-list">
6+
<h1>Shopping List for {this.props.name}</h1>
7+
<ul>
8+
<li>Instagram</li>
9+
<li>WhatsApp</li>
10+
<li>Oculus</li>
11+
</ul>
12+
</div>
13+
)
14+
}
15+
}
16+
17+
// Example usage: <ShoppingList name="Mark" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference types="cypress" />
2+
import Square from './square1.jsx'
3+
import React from 'react'
4+
import { mount } from 'cypress-react-unit-tests'
5+
6+
it('renders', () => {
7+
mount(<Square />)
8+
cy.on('window:alert', cy.stub().as('alerted'))
9+
cy.get('.square').click()
10+
cy.get('@alerted')
11+
.should('have.been.calledOnce')
12+
.and('have.been.calledWithExactly', 'click')
13+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
export default class Square extends React.Component {
3+
render() {
4+
return (
5+
<button className="square" onClick={() => alert('click')}>
6+
{this.props.value}
7+
</button>
8+
)
9+
}
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="cypress" />
2+
import Square from './square2.jsx'
3+
import React from 'react'
4+
import { mount } from 'cypress-react-unit-tests'
5+
6+
it('renders', () => {
7+
mount(<Square value="X" />)
8+
cy.on('window:alert', cy.stub().as('alerted'))
9+
cy.get('.square')
10+
.should('have.text', 'X')
11+
.click()
12+
cy.get('@alerted')
13+
.should('have.been.calledOnce')
14+
.and('have.been.calledWithExactly', 'click')
15+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
export default class Square extends React.Component {
3+
constructor(props) {
4+
super(props)
5+
this.state = {
6+
value: null,
7+
}
8+
}
9+
10+
render() {
11+
return (
12+
<button className="square" onClick={() => alert('click')}>
13+
{this.props.value}
14+
</button>
15+
)
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference types="cypress" />
2+
import Square from './square3.jsx'
3+
import React from 'react'
4+
import { mount } from 'cypress-react-unit-tests'
5+
6+
it('renders', () => {
7+
mount(<Square />)
8+
cy.get('.square')
9+
.should('have.text', '')
10+
.click()
11+
cy.contains('.square', 'X')
12+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
export default class Square extends React.Component {
3+
constructor(props) {
4+
super(props)
5+
this.state = {
6+
value: null,
7+
}
8+
}
9+
10+
render() {
11+
return (
12+
<button className="square" onClick={() => this.setState({ value: 'X' })}>
13+
{this.state.value}
14+
</button>
15+
)
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="cypress" />
2+
import Square from './square4.jsx'
3+
import React from 'react'
4+
import { mount } from 'cypress-react-unit-tests'
5+
6+
it('renders', () => {
7+
const onClick = cy.stub()
8+
mount(<Square value="O" onClick={onClick} />)
9+
cy.get('.square')
10+
.should('have.text', 'O')
11+
.click()
12+
.then(() => {
13+
expect(onClick).to.have.been.calledOnce
14+
})
15+
})

0 commit comments

Comments
 (0)