Skip to content

Commit d14c415

Browse files
committed
chore: add test
1 parent 18b0964 commit d14c415

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

packages/ui/src/components/SignUp/__tests__/SignUpStart.test.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ClerkAPIResponseError } from '@clerk/shared/error';
12
import { OAUTH_PROVIDERS } from '@clerk/shared/oauth';
23
import type { SignUpResource } from '@clerk/shared/types';
34
import { describe, expect, it, vi } from 'vitest';
@@ -452,6 +453,45 @@ describe('SignUpStart', () => {
452453
);
453454
});
454455

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+
455495
it('removes the ticket from the url when completing the sign up', async () => {
456496
const { wrapper, fixtures } = await createFixtures(f => {
457497
f.withEmailAddress();

0 commit comments

Comments
 (0)