|
| 1 | +import { ClerkAPIResponseError } from '@clerk/shared/error'; |
1 | 2 | import { OAUTH_PROVIDERS } from '@clerk/shared/oauth'; |
2 | 3 | import type { SignUpResource } from '@clerk/shared/types'; |
3 | 4 | import { describe, expect, it, vi } from 'vitest'; |
@@ -452,6 +453,45 @@ describe('SignUpStart', () => { |
452 | 453 | ); |
453 | 454 | }); |
454 | 455 |
|
| 456 | + it('does not throw when unsafeMetadata is set and signUp.create rejects with an API error', async () => { |
| 457 | + const { wrapper, fixtures, props } = await createFixtures(f => { |
| 458 | + f.withEmailAddress(); |
| 459 | + f.withPassword(); |
| 460 | + }); |
| 461 | + fixtures.signUp.create.mockRejectedValueOnce( |
| 462 | + new ClerkAPIResponseError('Error', { |
| 463 | + data: [ |
| 464 | + { |
| 465 | + code: 'form_password_pwned', |
| 466 | + long_message: 'Password has been found in an online data breach.', |
| 467 | + message: 'Password has been found in an online data breach.', |
| 468 | + meta: { param_name: 'password' }, |
| 469 | + }, |
| 470 | + ], |
| 471 | + status: 422, |
| 472 | + }), |
| 473 | + ); |
| 474 | + props.setProps({ unsafeMetadata: { foo: 'bar' } }); |
| 475 | + |
| 476 | + Object.defineProperty(window, 'location', { |
| 477 | + writable: true, |
| 478 | + value: { href: 'http://localhost/sign-up?__clerk_ticket=test_ticket' }, |
| 479 | + }); |
| 480 | + Object.defineProperty(window, 'history', { |
| 481 | + writable: true, |
| 482 | + value: { replaceState: vi.fn() }, |
| 483 | + }); |
| 484 | + |
| 485 | + render( |
| 486 | + <CardStateProvider> |
| 487 | + <SignUpStart /> |
| 488 | + </CardStateProvider>, |
| 489 | + { wrapper }, |
| 490 | + ); |
| 491 | + |
| 492 | + await waitFor(() => expect(fixtures.signUp.create).toHaveBeenCalled()); |
| 493 | + }); |
| 494 | + |
455 | 495 | it('removes the ticket from the url when completing the sign up', async () => { |
456 | 496 | const { wrapper, fixtures } = await createFixtures(f => { |
457 | 497 | f.withEmailAddress(); |
|
0 commit comments