Click a button
Default Checked Props: id and children
The propValue and options arguments are passed to
.findWrapperForClickButton to find a
ReactWrapper. The ReactWrapper will be
used to simulate events.
propValue(String): Value is compared with the values of the checked props to assert a match.options(Object): Optional.
propToCheck(String): Name of prop to check against instead of the default checked props.
Page object which invoked the method. This allow the method to be chained
with another Page object method.
If a ReactWrapper is found by
.findWrapperForClickButton, then the following events will
be simulated on the ReactWrapper's React element:
blurevent on the React element which is focused. This will occur if there is a focused React element and it is not the same as theReactWrapper's React element.focusevent on theReactWrapper's React element unless it is already in focus.clickevent on theReactWrapper's React element.submitevent on theReactWrapper's React element.
If no ReactWrapper is found, then an error is thrown.
import React, { Component } from 'react'
import Page from 'react-page-object'
class App extends Component {
state = { wasClicked: false }
onClick = event => this.setState({ wasClicked: true })
render() {
return (
<div>
{this.state.wasClicked ? 'was clicked' : 'was not clicked'}
<button id="button-id" onClick={this.onClick} />
<button onClick={this.onClick}>button text</button>
<button className="button-class" onClick={this.onClick} />
</div>
)
}
}
describe('clickButton', () => {
let page
beforeEach(() => {
page = new Page(<App />)
})
afterEach(() => {
page.destroy()
})
it('clicks the button - targeting id', () => {
expect(page.content()).toMatch(/was not clicked/)
page.clickButton('button-id')
expect(page.content()).toMatch(/was clicked/)
})
it('clicks the button - targeting children', () => {
expect(page.content()).toMatch(/was not clicked/)
page.clickButton('button text')
expect(page.content()).toMatch(/was clicked/)
})
it('clicks the button - targeting non-default prop', () => {
expect(page.content()).toMatch(/was not clicked/)
page.clickButton('button-class', { propToCheck: 'className' })
expect(page.content()).toMatch(/was clicked/)
})
})