Skip to content

Jest / Vitest

Both Jest and Vitest share the same API, so the integration is identical.

Setup

Install the MailOven client:

sh
npm install -D @mailoven/client
sh
yarn add -D @mailoven/client
sh
pnpm add -D @mailoven/client
sh
bun add -D @mailoven/client
sh
deno add -D npm:@mailoven/client

Example: verify email content

typescript
// test/notifications.test.ts
import { describe, it, expect, beforeEach } from "vitest"; // or "jest"
import { MailOvenClient } from "@mailoven/client";

const mailoven = new MailOvenClient({
  apiKey: process.env.MAILOVEN_API_KEY!,
  slug: "acme",
});

describe("Order notifications", () => {
  // inbox is the local part of the address (before @)
  const inbox = "orders";

  it("sends order confirmation email", async () => {
    const since = new Date();

    // Trigger your app to send an email
    await fetch("http://localhost:3000/api/orders", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        email: mailoven.getEmailAddress(inbox),
        product: "Widget",
      }),
    });

    // Wait for the email to arrive, only considering emails received after the test started
    const email = await mailoven.waitForEmail({
      to: inbox,
      since,
      filter: { subject: "Order confirmation" },
    });

    expect(email.subject).toContain("Order confirmation");
    expect(email.bodyText).toContain("Widget");
    expect(email.fromAddress).toBe("orders@myapp.com");
  });

  it("sends shipping notification", async () => {
    const since = new Date();

    // ... trigger shipping notification

    const email = await mailoven.waitForEmail(
      { to: inbox, since, filter: { subject: "shipped" } },
      { timeout: 15_000 },
    );

    expect(email.bodyText).toContain("tracking");
  });
});

Disposable email inboxes for every teams