Skip to content

Jest

Terminal window
npm install --save-dev @inboxical/sdk

Add your API key to the test environment:

.env.test
INBOXICAL_API_KEY=ixk_live_...
email.test.ts
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=')
})
})
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!)
})

Each createInbox() call returns a unique address — run tests in parallel safely:

jest.config.ts
export default {
maxWorkers: 8, // each worker gets its own inboxes
}
  • Use afterEach to delete inboxes — keeps your dashboard clean
  • timeout: 30 is usually enough; increase for slow email flows
  • Store the API key in CI as a secret: INBOXICAL_API_KEY