Cucumber
Setup
Install the MailOven client:
sh
npm install -D @mailoven/clientsh
yarn add -D @mailoven/clientsh
pnpm add -D @mailoven/clientsh
bun add -D @mailoven/clientCreate a MailOven world helper:
typescript
// features/support/mailoven.ts
import { MailOvenClient } from "@mailoven/client";
export const mailoven = new MailOvenClient({
apiKey: process.env.MAILOVEN_API_KEY,
slug: process.env.MAILOVEN_SLUG,
});Step definitions
typescript
// features/support/email-steps.ts
import { Given, When, Then } from "@cucumber/cucumber";
import { expect } from "chai";
import { mailoven } from "./mailoven";
Given("the {string} inbox is empty", async function (inbox: string) {
await mailoven.deleteInbox(inbox);
});
When("I wait for an email to {string}", async function (inbox: string) {
this.lastEmail = await mailoven.waitForEmail({ to: inbox });
});
When(
"I wait for an email to {string} with subject {string}",
async function (inbox: string, subject: string) {
this.lastEmail = await mailoven.waitForEmail({
to: inbox,
filter: { subject },
});
},
);
Then("the email subject should contain {string}", function (text: string) {
expect(this.lastEmail.subject).to.include(text);
});
Then("the email body should contain {string}", function (text: string) {
expect(this.lastEmail.bodyText).to.include(text);
});
Then("I extract the link matching {string}", function (pattern: string) {
const match = this.lastEmail.bodyText.match(new RegExp(pattern));
expect(match).to.not.be.null;
this.extractedLink = match![1] || match![0];
});Feature file
gherkin
# features/signup.feature
Feature: User signup
Background:
Given the "signup-test" inbox is empty
Scenario: Signup sends verification email
Given I am on the signup page
When I fill in "email" with "signup-test@acme.mailoven.com"
And I fill in "password" with "securepassword123"
And I click "Sign up"
And I wait for an email to "signup-test" with subject "Verify"
Then the email subject should contain "Verify"
And the email body should contain "click"