Skip to content
You're viewing documentation for v0.6.4. It may be out of date.Go to latest
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Test email behavior

Assert sends, fallback routing, and retries in unit tests with the memory adapter, failing adapter, and capture plugin — no provider account needed.

This guide tests email behavior without network calls: prove a send happened with the right fields, prove the fallback route engages when the primary fails, and prove retries fire. Everything runs in plain unit tests — the examples use bun:test, but any runner works.

Two tools cover it all, both free of provider credentials:

Assert a send happened with the right fields

memoryProvider() registers like any adapter but stores every message in raw.sent instead of calling an API. Plugins, defaults, and validation all run, so you assert the message the provider actually received:

This also catches plugin transforms — mount a defaults plugin on the test client and assert the merged headers or reply-to landed on message.

Assert the fallback engaged when the primary fails

failingProvider("primary") throws on every send. Pair it with a memory backup and the same fallback order production uses:

Use the same message fields production sends. A backup adapter that cannot carry one of them fails this test now instead of failing during an outage.

Assert retry events with the capture plugin

The capture plugin extends the client with email.capture.events. To see a retry event, you need an adapter that fails with a retryable error and then succeeds — a five-line inline adapter does it:

delay: () => 0 keeps the backoff out of your test runtime. failingProvider throws a plain Error (not retryable), so it tests fallback, not retries — retry tests need an error with retryable: true.

Clear stores between tests

Both stores are plain arrays behind a clear() method. Reset them in beforeEach when a client outlives a single test:

To assert capture events without going through the typed client extension, create the store yourself and hand it to the plugin:

Run the suite

No environment variables, no network. If a test makes a real HTTP call, an adapter slipped in — test clients should only register memoryProvider, failingProvider, or inline test adapters.

Next

Last updated on