forked from testing-library/preact-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents-compat.js
More file actions
25 lines (20 loc) · 829 Bytes
/
events-compat.js
File metadata and controls
25 lines (20 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { h } from 'preact' // required by render
import { fireEvent, render } from '..'
import 'preact/compat'
test('calling `fireEvent` with `preact/compat` and onChange works too', () => {
const handler = jest.fn()
// Preact only matches React's aliasing of `onChange` when `preact/compat` is used
// This test ensures this is supported properly with `fireEvent.change()`
const {
container: { firstChild: input }
} = render(<input type="text" onChange={handler} />)
const targetProperties = { value: 'a' }
const otherProperties = { isComposing: true }
const init = {
target: targetProperties,
...otherProperties
}
expect(fireEvent.change(input, init)).toBe(true)
expect(handler).toHaveBeenCalledTimes(1)
expect(handler).toHaveBeenCalledWith(expect.objectContaining(otherProperties))
})