summaryrefslogtreecommitdiff
path: root/src/components/ui/input.test.tsx
diff options
context:
space:
mode:
authorBertrand Yuan <189593334+bertyuan@users.noreply.github.com>2026-04-07 08:38:43 +0800
committerGitHub <noreply@github.com>2026-04-07 08:38:43 +0800
commit2ef9e56c390508f52d8734ba36fa4a23bec3558e (patch)
treeef5c68f99f0d976c2fc3e6a131d390935a870e53 /src/components/ui/input.test.tsx
parentae53c20c22b97440b7b0680bf823c523e9486441 (diff)
parent18fc18761dbefc2ab2fbaf93e1fe433eb0b47b37 (diff)
Merge pull request #15 from bertyuan/tast
A small portion of newly added unit testing code
Diffstat (limited to 'src/components/ui/input.test.tsx')
-rw-r--r--src/components/ui/input.test.tsx16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/components/ui/input.test.tsx b/src/components/ui/input.test.tsx
index aabe76f..036352b 100644
--- a/src/components/ui/input.test.tsx
+++ b/src/components/ui/input.test.tsx
@@ -1,6 +1,8 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, test } from 'vitest';
import { Input } from './input';
+import userEvent from '@testing-library/user-event';
+import { vi } from 'vitest';
describe('Input', () => {
test('renders an input with the expected slot attribute', () => {
@@ -18,5 +20,19 @@ describe('Input', () => {
expect(input).toHaveAttribute('type', 'password');
expect(input).toBeDisabled();
});
+
+ test('handles user typing and triggers onChange event', async () => {
+ const user = userEvent.setup();
+ const handleChange = vi.fn();
+
+ render(<Input aria-label="Username" onChange={handleChange} />);
+ const input = screen.getByLabelText('Username');
+
+ await user.type(input, 'hello world');
+
+ expect(input).toHaveValue('hello world');
+ expect(handleChange).toHaveBeenCalled();
+ expect(handleChange).toHaveBeenCalledTimes(11);
+ });
});