Skip to content

Cypress

Install the proxymail-qa package:

Terminal window
npm install --save-dev proxymail-qa

Cypress runs tasks in Node, so register them in the config. The API key comes from PROXYMAIL_QA_API_KEY in the environment Cypress runs in:

cypress.config.ts
import { defineConfig } from 'cypress';
import { ProxyMailQA } from 'proxymail-qa';
export default defineConfig({
e2e: {
setupNodeEvents(on) {
const qa = new ProxyMailQA(); // reads PROXYMAIL_QA_API_KEY
on('task', {
createAddress: () => qa.createAddress({ persona: true }),
waitForLink: ({ address, since }: { address: string; since: string }) => qa.waitForLink(address, { type: 'verify', since }),
deleteAddress: (address: string) => qa.deleteAddress(address).then(() => null),
});
},
},
});

Then sign up and open the link from the email:

cypress/e2e/signup.cy.js
it('verifies the email', () => {
cy.task('createAddress').then(({ address }) => {
const since = new Date().toISOString();
cy.visit('/signup');
cy.get('[name=email]').type(address);
cy.contains('Sign up').click();
cy.task('waitForLink', { address, since }, { timeout: 35000 }).then(({ value }) => cy.visit(value));
cy.task('deleteAddress', address);
});
});

The task timeout is 35 seconds because a wait can hold for up to 30. For a code instead of a link, add a task that calls qa.waitForCode(address, { since }) and type its value into the form.

If nothing arrives, the error says why as far as Proxy Mail QA can tell, for example that your app’s email provider only sends to verified addresses. For running in CI, see Running in CI. Prefer plain HTTP from the spec with cy.request? Every call is in the REST API guide.