Jest
Install
Section titled “Install”npm install --save-dev @inboxical/sdkAdd your API key to the test environment:
INBOXICAL_API_KEY=ixk_live_...Full example
Section titled “Full example”import { Inboxical } from '@inboxical/sdk'
const client = new Inboxical({ apiKey: process.env.INBOXICAL_API_KEY!,})
describe('User signup flow', () => { let inboxId: string
afterEach(async () => { if (inboxId) await client.deleteInbox(inboxId) })
it('sends a welcome email after registration', async () => { const inbox = await client.createInbox({ name: 'signup-test' }) inboxId = inbox.id
// Trigger your app await myApp.register({ email: inbox.email_address })
// Wait for the email (blocks up to 30s) const message = await client.waitForMessage(inbox.id, { timeout: 30 })
expect(message.subject).toBe('Welcome to MyApp!') expect(message.to_addrs).toContain(inbox.email_address) })
it('sends a password reset email', async () => { const inbox = await client.createInbox({ name: 'reset-test' }) inboxId = inbox.id
await myApp.register({ email: inbox.email_address }) await myApp.requestPasswordReset(inbox.email_address)
const message = await client.waitForMessage(inbox.id, { timeout: 30 })
expect(message.subject).toContain('Reset your password') expect(message.body_html).toContain('/reset-password?token=') })})Extracting verification codes
Section titled “Extracting verification codes”it('extracts OTP from verification email', async () => { const inbox = await client.createInbox() inboxId = inbox.id
await myApp.register({ email: inbox.email_address })
const message = await client.waitForMessage(inbox.id, { timeout: 30 }) const code = client.extractCode(message)
expect(code).toBeDefined() expect(code).toMatch(/^\d{4,8}$/)
// Use the code to complete verification await myApp.verify(inbox.email_address, code!)})Parallel tests
Section titled “Parallel tests”Each createInbox() call returns a unique address — run tests in parallel safely:
export default { maxWorkers: 8, // each worker gets its own inboxes}- Use
afterEachto delete inboxes — keeps your dashboard clean timeout: 30is usually enough; increase for slow email flows- Store the API key in CI as a secret:
INBOXICAL_API_KEY