cypress-mailhog
    TypeScript icon, indicating that this package has built-in type declarations

    1.4.0Β β€’Β PublicΒ β€’Β Published

    cypress-mailhog

    A collection of usefull Cypress commands for MailHog πŸ—. This package supports TypeScript out of the box.

    Setup

    Install this package via NPM:

    npm install --dev cypress-mailhog

    Include this package into your Cypress command file:

    // cypress/support/commands.js
    import 'cypress-mailhog';

    Add the base url of your MailHog installation to your cypress.json:

    {
      ...
      "mailHogUrl": "http://localhost:8090"
    }

    Commands

    Mail Collection

    mhGetAllMails()

    Yields an array of all the mails stored in MailHog.

    cy
      .mhGetAllMails()
      .should('have.length', 1);

    mhGetMailsBySubject( subject )

    Yields an array of all mails with given subject.

    cy
      .mhGetMailsBySubject('My Subject')
      .should('have.length', 1);

    mhGetMailsBySender( from )

    Yields an array of all mails with given sender.

    cy
      .mhGetMailsBySender('sender@example.com')
      .should('have.length', 1);

    mhGetMailsByRecipient( recipient )

    Yields an array of all mails with given recipient.

    cy
      .mhGetMailsByRecipient('recipient@example.com')
      .should('have.length', 1);

    mhFirst()

    Yields the first mail of the loaded selection.

    cy
      .mhGetAllMails()
      .mhFirst();

    mhDeleteAll()

    Deletes all stored mails from MailHog.

    cy.mhDeleteAll();

    Handling a Single Mail βœ‰οΈ

    mhGetSubject()

    Yields the subject of the current mail.

    cy
      .mhGetAllMails()
      .mhFirst()
      .mhGetSubject()
      .should('eq', 'My Mails Subject');

    mhGetBody()

    Yields the body of the current mail.

    cy
      .mhGetAllMails()
      .mhFirst()
      .mhGetBody()
      .should('contain', 'Part of the Message Body');

    mhGetSender()

    Yields the sender of the current mail.

    cy
      .mhGetAllMails()
      .mhFirst()
      .mhGetSender()
      .should('be', 'sender@example.com');

    mhGetRecipients()

    Yields the sender of the current mail.

    cy
      .mhGetAllMails()
      .mhFirst()
      .mhGetRecipients()
      .should('contain', 'recipient@example.com');

    Asserting the Mail Collection πŸ”

    mhHasMailWithSubject( subject )

    Asserts if there is a mail with given subject.

    cy.mhHasMailWithSubject('My Subject');

    mhHasMailFrom( from )

    Asserts if there is a mail from given sender.

    cy.mhHasMailFrom('sender@example.com');

    mhHasMailTo( recipient )

    Asserts if there is a mail to given recipient (looks for "To", "CC" and "BCC").

    cy.mhHasMailTo('recipient@example.com');

    Jim Chaos Monkey 🐡

    mhGetJimMode()

    Returns if Jim is enabled / disabled.

    cy
      .mhGetJimMode()
      .should('eq', true);

    mhSetJimMode( enabled )

    Enables / Disables Jim chaos monkey.

    cy
      .mhSetJimMode(true)
      .mhGetJimMode()
      .should('eq', true);

    Package Development

    Start Local Test Server

    Navigate into the test-server directory.

    cd ./test-server/

    Install dependencies.

    composer install
    yarn # or npm install

    Start docker server.

    docker-compose up

    Open the Testpage in your browser: http://localhost:8080/cypress-mh-tests/ Open MailHog in your browser: http://localhost:8090/

    Open the Cypress testclient.

    yarn cypress:open

    Install

    npm i cypress-mailhog

    DownloadsWeekly Downloads

    6,622

    Version

    1.4.0

    License

    GPL-2.0

    Unpacked Size

    27.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • smenigat