How to Test Clerk Email Verification Codes
Clerk makes auth easy to add — and it emails your users a one-time verification code on signup and sign-in. Testing that flow means reading the code Clerk sends, which is exactly where a disposable inbox helps. Here’s how.
What Clerk emails
With email-code verification (Clerk’s common passwordless setup), a user enters their email and Clerk emails a one-time code — typically six digits — to type back in. (Clerk can also send magic links.) Either way, your test needs to read that code from the email.
Clerk has a test mode, too: Clerk ships fixed test values — a +clerk_test email subaddress and the code 424242 — great for fast unit-style tests. Use a disposable inbox when you want to test the real end-to-end flow: an actual email sent and received.
Sign up with a disposable address
const inbox = await createInbox(`clerk-${Date.now()}`)
await page.goto('https://your-app.com/sign-up')
await page.getByLabel('Email address').fill(inbox.address)
await page.getByRole('button', { name: /continue/i }).click()(The createInbox/waitForEmail helpers come from the CI/CD guide.)
Read the code from the email
// Clerk emails a one-time code — read it straight from extractedCodes
const email = await waitForEmail(inbox._id, 'has_code=true')
const code = email.extractedCodes[0] // e.g. "920183"
await page.getByLabel(/verification code/i).fill(code)
await page.getByRole('button', { name: /verify|continue/i }).click()
await expect(page).toHaveURL(/dashboard/)has_code=true makes /waitresolve only on the email that actually carries a code, so a welcome email can’t race it.
Magic links instead of codes
If you’ve configured Clerk for email magic links, read primaryLink and navigate to it:
const email = await waitForEmail(inbox._id, 'subject=' + encodeURIComponent('sign in'))
await page.goto(email.primaryLink)Tips
- Use Clerk’s test mode (
424242) for fast unit tests; use a disposable inbox for true end-to-end coverage. - A unique inbox per test keeps parallel runs from sharing mail.
- Clerk codes are usually six digits —
extractedCodes[0]handles it; fall back to amatchregex for any custom format.
Related reading
Try it in two minutes
Create a disposable prefix@devmailr.app inbox over the API, send mail to it from your app, and read it in your tests. Free plan, no card required.