-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move onChange test to separate file
onChange test requires import from preact/compat which affects other tests in the same test file so I moved it to separate file
- Loading branch information
1 parent
61ac9a7
commit 01e9336
Showing
3 changed files
with
28 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { h } from 'preact' // required by render | ||
import { fireEvent, render } from '..' | ||
import { forwardRef } from 'preact/compat' // required for this test to make sense | ||
|
||
test('calling `fireEvent` with `preact/compat` and onChange works too', () => { | ||
const handler = jest.fn() | ||
|
||
// forwardRef needs to be imported from preact/compat for this test to make sense. | ||
// Preact behavior when using onChange is described here: | ||
// https://preactjs.com/guide/v10/differences-to-react#use-oninput-instead-of-onchange | ||
// We want to test if onChange event gets caught 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)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters