Check a checkbox
Default Checked Props: id and name
The propValue and options arguments are passed to
.findWrapperForCheck 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
.findWrapperForCheck, 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.changeevent on theReactWrapper's React element.
If no ReactWrapper is found, then an error is thrown.
.findWrapperForCheck(propValue[, options]) => ReactWrapper.uncheck(propValue[, options]) => ReactWrapper
import React, { Component } from 'react'
import Page from 'react-page-object'
class App extends Component {
state = { checked: false }
onChange = event => this.setState({ checked: event.target.checked })
render() {
return (
<div>
{this.state.checked ? 'is checked' : 'is not checked'}
<input
id="input-id"
type="checkbox"
onChange={this.onChange}
checked={this.state.checked}
/>
<input
name="input-name"
type="checkbox"
onChange={this.onChange}
checked={this.state.checked}
/>
<input
className="input-class"
type="checkbox"
onChange={this.onChange}
checked={this.state.checked}
/>
</div>
)
}
}
describe('check', () => {
let page
beforeEach(() => {
page = new Page(<App />)
})
afterEach(() => {
page.destroy()
})
it('checks the input - targeting id', () => {
expect(page.content()).toMatch(/is not checked/)
page.check('input-id')
expect(page.content()).toMatch(/is checked/)
})
it('checks the input - targeting name', () => {
expect(page.content()).toMatch(/is not checked/)
page.check('input-name')
expect(page.content()).toMatch(/is checked/)
})
it('checks the input - targeting non-default prop', () => {
expect(page.content()).toMatch(/is not checked/)
page.check('input-class', { propToCheck: 'className' })
expect(page.content()).toMatch(/is checked/)
})
})