Deterministic Email Testing

Test every email without sending a real message or mocking HTTP libraries.

InMemoryTransport & InMemoryInbox

@mailport/testing provides a zero-network transport that captures outgoing messages in an inspectable memory inbox.

import { describe, expect, it } from 'vitest';
import { InMemoryTransport, createTestMailer } from '@mailport/testing';

describe('User Registration Email', () => {
  it('captures welcome email without network calls', async () => {
    const transport = new InMemoryTransport();
    const mailer = createTestMailer({ transport });

    await mailer.send({
      from: 'app@example.com',
      to: 'user@example.com',
      subject: 'Welcome to App',
      text: 'Thanks for signing up.',
    });

    expect(transport.inbox.count).toBe(1);
    const latest = transport.inbox.latest();
    expect(latest?.to[0].address).toBe('user@example.com');
  });
});