Skip to content

Commit 317e616

Browse files
committed
test(text-input-otp): add test for clear function
- add test case to verify that the clear function clears input text when called programmatically - ensure that the cleared text is not visible in the component after calling clear
1 parent 371889e commit 317e616

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/__tests__/text-input-otp.test.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,22 @@ describe('TextInputOTP Component', () => {
5858
<TextInputOTPSlot index={2} />
5959
</TextInputOTP>
6060
);
61-
6261
act(() => ref.current?.setValue(CODE));
63-
6462
expect(mockedOnFilled).toHaveBeenCalledWith(CODE);
6563
});
64+
65+
it('should call clear the input text when clear function is called programmatically', () => {
66+
const CODE = '1';
67+
const ref = createRef<TextInputOTPRef>();
68+
const view = render(
69+
<TextInputOTP ref={ref} maxLength={3}>
70+
<TextInputOTPSlot index={0} />
71+
<TextInputOTPSlot index={1} />
72+
<TextInputOTPSlot index={2} />
73+
</TextInputOTP>
74+
);
75+
fireEvent.changeText(view.getByTestId('hidden-text-input'), CODE);
76+
act(() => ref.current?.clear());
77+
expect(view.queryByText(CODE)).toBeFalsy();
78+
});
6679
});

0 commit comments

Comments
 (0)