This library gives you the ability to write the following integration tests:
importReact,{Component}from'react'importPagefrom'react-page-object'classCounterextendsComponent{state={count: 0}addOne=()=>this.setState({count: this.state.count+1})addOneAsync=()=>setTimeout(this.addOne,100)render(){return(<div><h1>{this.state.count}</h1><buttononClick={this.addOne}>Add one</button><buttononClick={this.addOneAsync}>Add one async</button></div>)}}describe('Counter component',()=>{letpagebeforeEach(()=>{page=newPage(<Counter/>)})afterEach(()=>{page.destroy()})it('sets the initial count to 0',()=>{expect(page.content()).toMatch(/0/)})it('adds one to the count when the \'Add one\' button is clicked',()=>{page.clickButton('Add one')expect(page.content()).toMatch(/1/)})it('adds one to the count after a delay when the \'Add one async\' button is clicked',async()=>{page.clickButton('Add one async')expect(page.content()).not.toMatch(/1/)awaitpage.waitUntil(()=>page.contentMatches(/1/))expect(page.content()).toMatch(/1/)})})This was test written in Jest. However, This library can be used with any test
runner or assertion library that is compatible with
Enzyme.
$ npm install --save-dev react-page-object
enzyme is a peer dependency of react-page-object, so you will need to
install it if you have not done so already. Additionally, react-dom and
react-addons-test-utils are peer dependencies of enzyme, so install those
as well if you are missing them.
$ npm install --save-dev enzyme
$ npm install --save-dev react-dom
$ npm install --save-dev react-test-renderer
If you are new to testing in React, check out the following guides to get you up and running:
- Set up with Jest in Create React App (Recommended)
- Set up Karma with Mocha and Chai in Create React App
- Set up Karma with Jasmine in Create React App
Create a Page object
Destroy a Page object
Find a checkbox
Find a radio button
Find a button
Find a clickable input
Find a link
Find a text input
Find a textarea
Find a select box
Blur the currently focused element.
Check a checkbox
Choose a radio button
Click a button
Click a clickable input
Click a link
Fill in a text input
Fill in a textarea
Select an option from a select box
Uncheck a checkbox
Returns the page text
Returns whether or not the page text matches the given matcher
Returns the current URL path
Output to the console a code snippet to view the page HTML
Wait until a certain condition is met. Useful for testing asynchronicity