You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a Number component with an onChange handler that calls back to the container.
Create a test where Number component is rendered with an onChange func created with jest.fn(). Use userEvent to click into the field and then simulate a down-arrow keyboard press.
For example:
test('the value can be changed with arrow up & down', async () => {
const initialValue = '7';
const minValue = '5';
const onChange = jest.fn();
render(<NumberField label={LABEL} value={initialValue} onChange={onChange} min={minValue} />);
const input = screen.getByRole('spinbutton');
await userEvent.click(input);
await userEvent.keyboard('{arrowdown}');
expect(onChange).toBeCalledWith('6');
})
Expected behavior
Expected behaviour is for the test to pass. Pressing the down arrow in a browser would cause the number value to reduce by 1 (assuming step=1).
Actual behavior
Upon running the tests, the test fails with the following result:
expect(jest.fn()).toBeCalledWith(...expected)
Expected: "6"
Number of calls: 0
> 64 | expect(onChange).toBeCalledWith('6');
| ^
65 | });
66 | });
Reproduction example
https://codesandbox.io/s/eloquent-tristan-ixhpuv?file=/src/number.test.js
Prerequisites
Number
component with anonChange
handler that calls back to the container.Number
component is rendered with anonChange
func created withjest.fn()
. UseuserEvent
to click into the field and then simulate a down-arrow keyboard press.For example:
Expected behavior
Expected behaviour is for the test to pass. Pressing the down arrow in a browser would cause the number value to reduce by 1 (assuming
step=1
).Actual behavior
Upon running the tests, the test fails with the following result:
User-event version
14.4.3
Environment
Testing Library framework: @testing-library/[email protected]
JS framework:
[email protected]
Test environment:
[email protected]
DOM implementation:
[email protected]
Additional context
No response
The text was updated successfully, but these errors were encountered: