Skip to content

Commit

Permalink
test(16207): adds NumberInput test coverage of allowEmpty (#16254)
Browse files Browse the repository at this point in the history
  • Loading branch information
2nikhiltom committed Apr 29, 2024
1 parent 9c1dc9c commit b4e010d
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,36 @@ describe('NumberInput', () => {

expect(onChange).toHaveBeenCalledTimes(0);
});

it('should update value to empty when allowEmpty is true & input value becomes empty', async () => {
const onChange = jest.fn();
render(
<NumberInput
id="carbon-number"
min={-100}
max={100}
value={50}
label="NumberInput label"
helperText="Optional helper text."
invalidText="Number is not valid"
allowEmpty={true}
onChange={onChange}
/>
);

const input = screen.getByLabelText('NumberInput label');

await userEvent.clear(input);

userEvent.type(input, '{backspace}');
expect(input.value).toBe('');
expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
target: expect.any(Object),
}),
expect.objectContaining({
value: '',
})
);
});
});

0 comments on commit b4e010d

Please sign in to comment.