forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello-act-spec.js
32 lines (27 loc) · 836 Bytes
/
hello-act-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
// example from https://reactjs.org/docs/testing-recipes.html
import React from 'react'
import { mount } from 'cypress-react-unit-test'
function Hello(props) {
if (props.name) {
return <h1>Hello, {props.name}!</h1>
} else {
return <span>Hey, stranger</span>
}
}
// shows multiple mount commands
it('renders with or without a name', () => {
mount(<Hello />)
cy.contains('Hey, stranger').should('be.visible')
mount(<Hello name="Jenny" />)
cy.contains('h1', 'Hello, Jenny!').should('be.visible')
mount(<Hello name="Margaret" />)
cy.contains('h1', 'Hello, Margaret!').should('be.visible')
})
// data-driven testing
const names = ['Jenny', 'Margaret']
names.forEach(name => {
it(`greets ${name}`, () => {
mount(<Hello name={name} />)
cy.contains('h1', `Hello, ${name}!`).should('be.visible')
})
})