new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Better Auth · Plugins · all subjects

test-utils/examples

3 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Test Utils integration test example with Vitest

Example integration test using Vitest that demonstrates creating a user, getting authenticated headers, testing an authenticated request, and cleaning up: describe('protected route', () => { let test; beforeAll(async () => { const ctx = await auth.$context; test = ctx.test }); it('should return user data for authenticated request', async () => { const user = test.createUser({ email: 'test@example.com' }); await test.saveUser(user); const headers = await test.getAuthHeaders({ userId: user.id }); const session = await auth.api.getSession({ headers }); expect(session?.user.id).toBe(user.id); await test.deleteUser(user.id) }) })

Test Utils E2E test example with Playwright

Example E2E test using Playwright that demonstrates creating a user, getting cookies, injecting them into the browser context, navigating to a protected page, and verifying the user name is visible: test('dashboard shows user name', async ({ context, page }) => { const ctx = await auth.$context; const testUtils = ctx.test; const user = testUtils.createUser({ email: 'e2e@example.com', name: 'E2E User' }); await testUtils.saveUser(user); const cookies = await testUtils.getCookies({ userId: user.id, domain: 'localhost' }); await context.addCookies(cookies); await page.goto('/dashboard'); await expect(page.getByText('E2E User')).toBeVisible(); await testUtils.deleteUser(user.id) })

Test Utils OTP verification test example

Example OTP verification test using Vitest that demonstrates clearing OTPs, creating a user with emailVerified false, sending a verification OTP, retrieving the captured OTP, verifying the email, and cleaning up: describe('OTP verification', () => { let test; beforeAll(async () => { const ctx = await auth.$context; test = ctx.test }); beforeEach(() => { test.clearOTPs() }); it('should verify email with captured OTP', async () => { const email = 'otp-test@example.com'; const user = test.createUser({ email, emailVerified: false }); await test.saveUser(user); await auth.api.sendVerificationOTP({ body: { email, type: 'email-verification' } }); const otp = test.getOTP(email); expect(otp).toBeDefined(); await auth.api.verifyEmail({ body: { email, otp } }); await test.deleteUser(user.id) }) })

Give your agent this brain