Fill in a text input
Default Checked Props: id, name, and placeholder
The propValue and options arguments are passed to
.findWrapperForFillIn 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.eventTargetValue(String): Value which will equalevent.target.valueinonChangeevent handlers triggered by the simulatedchangeevent.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
.findWrapperForFillIn, 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. ForonChangeevent handlers triggered by this simulatedchangeevent,event.target.valuewill equaleventTargetValue.
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 = { text: '' }
onChange = event => this.setState({ text: event.target.value })
render() {
return (
<div>
{this.state.text}
<input id="input-id" onChange={this.onChange} />
<input name="input-name" onChange={this.onChange} />
<input placeholder="input-placeholder" onChange={this.onChange} />
<input className="input-class" onChange={this.onChange} />
</div>
)
}
}
describe('fillIn', () => {
let page
beforeEach(() => {
page = new Page(<App />)
})
afterEach(() => {
page.destroy()
})
it('fills in the input - targeting id', () => {
page.fillIn('input-id', 'hello')
expect(page.content()).toMatch(/hello/)
})
it('fills in the input - targeting name', () => {
page.fillIn('input-name', 'hello')
expect(page.content()).toMatch(/hello/)
})
it('fills in the input - targeting placeholder', () => {
page.fillIn('input-placeholder', 'hello')
expect(page.content()).toMatch(/hello/)
})
it('fills in the input - targeting non-default prop', () => {
page.fillIn('input-class', 'hello', { propToCheck: 'className' })
expect(page.content()).toMatch(/hello/)
})
})