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

Commit 6751f42

Browse files
committed
add react-bootstrap modal test, closes #33
1 parent 92289a8 commit 6751f42

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react'
2+
import { Button, Modal } from 'react-bootstrap'
3+
import { mount } from 'cypress-react-unit-test'
4+
5+
export class Example extends React.Component {
6+
constructor(props, context) {
7+
super(props, context)
8+
9+
this.handleShow = this.handleShow.bind(this)
10+
this.handleClose = this.handleClose.bind(this)
11+
12+
this.state = {
13+
show: true,
14+
}
15+
}
16+
17+
handleClose() {
18+
this.setState({ show: false })
19+
}
20+
21+
handleShow() {
22+
this.setState({ show: true })
23+
}
24+
25+
render() {
26+
return (
27+
<div>
28+
This text is all that renders. And the modal is not rendered, regardless
29+
of whether it is contained within this div.
30+
<Modal show={this.state.show} onHide={this.handleClose}>
31+
<Modal.Header closeButton>
32+
<Modal.Title>Modal heading</Modal.Title>
33+
</Modal.Header>
34+
<Modal.Body>
35+
<h4>Text in a modal</h4>
36+
<p>
37+
Cras mattis consectetur purus sit amet fermentum. Cras justo odio,
38+
dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta
39+
ac consectetur ac, vestibulum at eros.
40+
</p>
41+
</Modal.Body>
42+
<Modal.Footer>
43+
<Button onClick={this.handleClose}>Close</Button>
44+
</Modal.Footer>
45+
</Modal>
46+
</div>
47+
)
48+
}
49+
}
50+
51+
describe('react-bootstrap Modal', () => {
52+
it('works', () => {
53+
mount(<Example />, {
54+
cssFile: 'node_modules/bootstrap/dist/css/bootstrap.min.css',
55+
})
56+
// confirm modal is visible
57+
cy.contains('h4', 'Text in a modal').should('be.visible')
58+
cy.contains('button', 'Close').click()
59+
cy.contains('h4', 'Text in a modal').should('not.exist')
60+
})
61+
})

0 commit comments

Comments
 (0)