Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('getInputProps composes onChange with onInput', () => {
const onChange = jest.fn()
const onInput = jest.fn()
const Input = jest.fn(props => <input>)
const {ui} = setup({
children({getInputProps}) {
return (
<div>
<input>
</div>
)
},
})
render(ui)
expect(Input).toHaveBeenCalledTimes(1)
const [[firstArg]] = Input.mock.calls
expect(firstArg).toMatchObject({
onInput: expect.any(Function),
})
expect(firstArg.onChange).toBeUndefined()
const fakeEvent = {defaultPrevented: false, target: {value: ''}}
firstArg.onInput(fakeEvent)
expect(onChange).toHaveBeenCalledTimes(1)
expect(onChange).toHaveBeenCalledWith(fakeEvent)
expect(onInput).toHaveBeenCalledTimes(1)
expect(onInput).toHaveBeenCalledWith(fakeEvent)
})
test('works with preact', () => {
const childrenSpy = jest.fn(({getInputProps, getItemProps}) => (
<div>
<input>
<div>
<div>foo</div>
<div>bar</div>
</div>
</div>
))
const ui = {childrenSpy}
render(ui)
expect(childrenSpy).toHaveBeenCalledWith(
expect.objectContaining({
isOpen: false,
highlightedIndex: null,
selectedItem: null,
inputValue: '',
}),
)
})