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

Commit 9d49151

Browse files
committed
add counter with hooks spec
1 parent 5d7b3e2 commit 9d49151

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Look at the examples in [cypress/component](cypress/component) folder. Here is t
6363
Spec | Description
6464
--- | ---
6565
[alert-spec.js](cypress/component/basic/alert-spec.js) | Component tries to use `window.alert`
66-
[counter-spec.js](cypress/component/basic/counter-spec.js) | Counter component that uses `this.state`
66+
[counter-set-state](cypress/component/basic/counter-set-state) | Counter component that uses `this.state`
67+
[counter-use-hooks](cypress/component/basic/counter-use-hooks) | Counter component that uses `useState` hook
6768
[emotion-spec.js](cypress/component/basic/emotion-spec.js) | Confirms the component is using `@emotion/core` and styles are set
6869
[error-boundary-spec.js](cypress/component/basic/error-boundar-spec.js) | Checks if an error boundary component works
6970
[pure-component-spec.js](cypress/component/basic/pure-component.spec.js) | Tests stateless component
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import { mount } from 'cypress-react-unit-test'
3+
import Counter from './counter.jsx'
4+
5+
describe('Counter using hooks', () => {
6+
it('works', () => {
7+
mount(<Counter />)
8+
cy.contains('You clicked 0 times')
9+
cy.contains('Click me')
10+
.click()
11+
.click()
12+
.click()
13+
cy.contains('You clicked 3 times')
14+
})
15+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, { useState } from 'react'
2+
3+
// example from https://reactjs.org/docs/hooks-state.html
4+
function Counter() {
5+
// Declare a new state variable, which we'll call "count"
6+
const [count, setCount] = useState(0)
7+
8+
return (
9+
<div>
10+
<p>You clicked {count} times</p>
11+
<button onClick={() => setCount(count + 1)}>Click me</button>
12+
</div>
13+
)
14+
}
15+
16+
export default Counter

cypress/component/basic/transpiled-spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/// <reference types="../../lib" />
33
import { Transpiled } from './transpiled.jsx'
44
import React from 'react'
5-
import ReactDom from 'react-dom'
65
import { mount } from 'cypress-react-unit-test'
76

87
/* eslint-env mocha */

0 commit comments

Comments
 (0)