Find a select box
Default Checked Props: id and name
propValue(String): Value is compared with the values of the checked props to assert a match.childrenPropValueForOption(String): Value is compared with thechildrenprop value of childrenoptionReact elements for potentially matchingselectReact element.options(Object): Optional.
propToCheck(String): Name of prop to check against instead of the default checked props.showDebuggingInfo(Boolean): Iftrue, then messages detailing the process of finding aselectReact element will be outputted to the console.
ReactWrapper for a select React element whose:
idornameprop value equalspropValue- children include only one
optionReact element whosechildrenprop value equalschildrenPropValueForOption
If options.propToCheck is specified, then the method returns a
ReactWrapper for a select React element whose:
- value for the prop specified by
options.propToCheckequalspropValue - children include only one
optionReact element whosechildrenprop value equalschildrenPropValueForOption
import React from 'react'
import Page from 'react-page-object'
const App = () => (
<div>
<select id="select-id">
<option>option 1</option>
</select>
<select name="select-name">
<option>option 1</option>
</select>
<select className="select-class">
<option>option 1</option>
</select>
</div>
)
describe('findWrapperForSelect', () => {
let page, wrapper
beforeEach(() => {
page = new Page(<App />)
})
afterEach(() => {
page.destroy()
})
it('finds wrapper - targeting id', () => {
wrapper = page.findWrapperForSelect('select-id', 'option that does not exist')
expect(wrapper.exists()).toBe(false)
wrapper = page.findWrapperForSelect('select-id', 'option 1')
expect(wrapper.exists()).toBe(true)
})
it('finds wrapper - targeting name', () => {
wrapper = page.findWrapperForSelect('select-name', 'option 1')
expect(wrapper.exists()).toBe(true)
})
it('fills in the select - targeting non-default prop', () => {
wrapper = page.findWrapperForSelect('select-class', 'option 1')
expect(wrapper.exists()).toBe(false)
wrapper = page.findWrapperForSelect('select-class', 'option 1', { propToCheck: 'className' })
expect(wrapper.exists()).toBe(true)
})
})