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

Commit 06e003b

Browse files
committed
add counter spec
1 parent 11d5d37 commit 06e003b

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ describe('HelloState component', () => {
2727

2828
## Examples
2929

30-
* [cypress/integration/hello-world-spec.js](cypress/integration/hello-world-spec.js) - testing the simplest React component from [src/hello-world.jsx](src/hello-world.jsx)
31-
* [cypress/integration/hello-x-spec.js](cypress/integration/hello-x-spec.js) - testing React component with props and state [src/hello-x.jsx](src/hello-x.jsx)
32-
* [bahmutov/calculator](https://github.com/bahmutov/calculator) tests multiple components
30+
All components are in [src](src) folder. All tests are in [cypress/integration](cypress/integration) folder.
31+
32+
* [hello-world-spec.js](cypress/integration/hello-world-spec.js) - testing the simplest React component from [hello-world.jsx](src/hello-world.jsx)
33+
* [hello-x-spec.js](cypress/integration/hello-x-spec.js) - testing React component with props and state [hello-x.jsx](src/hello-x.jsx)
34+
* [counter-spec.js](cypress/integration/counter-spec.js) clicks on the component and confirms the result
35+
* separate repo [bahmutov/calculator](https://github.com/bahmutov/calculator) tests multiple components
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Counter } from '../../src/counter.jsx'
2+
import React from 'react'
3+
import { mount } from '../../lib'
4+
5+
/* eslint-env mocha */
6+
describe('Counter', () => {
7+
it('counts clicks', () => {
8+
mount(<Counter />)
9+
cy.contains('count: 0')
10+
.click()
11+
.contains('count: 1')
12+
.click()
13+
.contains('count: 2')
14+
})
15+
})

src/counter.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
3+
export class Counter extends React.Component {
4+
constructor (props) {
5+
super(props)
6+
this.state = {
7+
count: 0
8+
}
9+
}
10+
11+
click () {
12+
this.setState({
13+
count: this.state.count + 1
14+
})
15+
}
16+
17+
render () {
18+
return <p onClick={this.click.bind(this)}>count: {this.state.count}</p>
19+
}
20+
}

0 commit comments

Comments
 (0)