-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: onchange event with preact/compat enabled (#72)
* fix: fireEvent doesnt mirror onChange behavior when using preact/compat this fix aligns this library with testing-library for React where fireEvent.change() works as expected * 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 * refactor: simplify imports replace unnecessary forwardRef import with general preact/compat; improve commentary Co-authored-by: Ryan Christian <33403762+rschristian@users.noreply.github.com> * fix: apply aliasing only when preact/compat is used prevent applying aliasing when compat library is not used; add change event to basic event tests to ensure both cases work --------- Co-authored-by: Ryan Christian <33403762+rschristian@users.noreply.github.com>
- Loading branch information
1 parent
9fdc19b
commit 3e5394e
Showing
3 changed files
with
59 additions
and
5 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,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)) | ||
}) |
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