|
1 | 1 | import { ClerkRuntimeError } from '@clerk/shared/error'; |
2 | | -import { fireEvent, render, waitFor } from '@testing-library/react'; |
| 2 | +import { render, waitFor } from '@testing-library/react'; |
3 | 3 | import type { UserEvent } from '@testing-library/user-event'; |
4 | 4 | import userEvent from '@testing-library/user-event'; |
5 | | -import React from 'react'; |
6 | 5 | import { describe, expect, it, vi } from 'vitest'; |
7 | 6 |
|
8 | 7 | import { bindCreateFixtures } from '@/test/create-fixtures'; |
@@ -188,25 +187,24 @@ describe('CodeControl', () => { |
188 | 187 | const Component = createOTPComponent(onCodeEntryFinished); |
189 | 188 |
|
190 | 189 | const { getAllByTestId, getByLabelText } = render(<Component />, { wrapper }); |
| 190 | + const user = userEvent.setup(); |
191 | 191 |
|
192 | 192 | const input = getByLabelText(label); |
193 | | - const inputDivs = getAllByTestId(testId); |
194 | 193 |
|
195 | | - // Simulate autofill with mixed characters |
196 | | - fireEvent.change(input, { target: { value: '1a2b3c' } }); |
| 194 | + await user.click(input); |
| 195 | + await user.paste('1a2b3c'); |
197 | 196 |
|
198 | 197 | await waitFor(() => { |
199 | | - expect(inputDivs[0]).toBeEmptyDOMElement(); |
200 | | - expect(inputDivs[1]).toBeEmptyDOMElement(); |
201 | | - expect(inputDivs[2]).toBeEmptyDOMElement(); |
202 | | - expect(inputDivs[3]).toBeEmptyDOMElement(); |
203 | | - expect(inputDivs[4]).toBeEmptyDOMElement(); |
204 | | - expect(inputDivs[5]).toBeEmptyDOMElement(); |
| 198 | + expect(input).toHaveValue(''); |
205 | 199 | }); |
206 | 200 |
|
207 | | - // Simulate autofill with expected characters |
208 | | - fireEvent.change(input, { target: { value: '123456' } }); |
| 201 | + await user.paste('123456'); |
| 202 | + |
| 203 | + await waitFor(() => { |
| 204 | + expect(input).toHaveValue('123456'); |
| 205 | + }); |
209 | 206 |
|
| 207 | + const inputDivs = getAllByTestId(testId); |
210 | 208 | await waitFor(() => { |
211 | 209 | expect(inputDivs[0]).toHaveTextContent('1'); |
212 | 210 | expect(inputDivs[1]).toHaveTextContent('2'); |
|
0 commit comments