From 3df9d429dc20327b31d8ec56eccd5bbe90ede8af Mon Sep 17 00:00:00 2001 From: Victor Babel Date: Wed, 8 Jun 2022 10:00:23 -0700 Subject: [PATCH 1/2] test: assert event init is passed on to dom fireEvent --- src/__tests__/events.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/__tests__/events.js b/src/__tests__/events.js index 921c0b6..3cea179 100644 --- a/src/__tests__/events.js +++ b/src/__tests__/events.js @@ -152,6 +152,9 @@ eventTypes.forEach(({ type, events, elementType, init }) => { expect(fireEvent[eventName](ref.current, init)).toBe(true) expect(spy).toHaveBeenCalledTimes(1) + if (init) { + expect(spy).toHaveBeenCalledWith(expect.objectContaining(init)) + } }) }) }) @@ -164,9 +167,17 @@ test('onInput works', () => { container: { firstChild: input } } = render() - expect(fireEvent.input(input, { target: { value: 'a' } })).toBe(true) + const targetProperties = { value: 'a' } + const otherProperties = { isComposing: true } + const init = { + target: targetProperties, + ...otherProperties + } + + expect(fireEvent.input(input, init)).toBe(true) expect(handler).toHaveBeenCalledTimes(1) + expect(handler).toHaveBeenCalledWith(expect.objectContaining(otherProperties)) }) test('calling `fireEvent` directly works too', () => { @@ -176,14 +187,16 @@ test('calling `fireEvent` directly works too', () => { container: { firstChild: button } } = render(