
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@codeceptjs/mailslurp-helper
Advanced tools
MailSlurp helper for testing emails with MailSlurp service. MailSlurp creates disposable mailbox for each test and removes it after a test.
Register and obtain API key from MailSlurp.
npm i @codeceptjs/mailslurp-helper --save
Enable helper in codecept.conf.js.
helpers: {
MailSlurp: {
apiKey: '<insert api key here>',
require: '@codeceptjs/mailslurp-helper'
},
}
Use this helper in your tests to check email interactions. The most popular one
const mailbox = await I.haveNewMailbox();
// wait 10 seconds for an email
const email = await I.waitForLatestEmail(10);
I.seeInEmailSubject('Restore Password');
I.seeInEmailBody('Click link to restore password');
const restoreUrl = email.body.match(/http(s):\/\/(.*?)\s/)[0];
I.amOnPage(restoreUrl);
const mailbox1 = await I.haveNewMailbox();
const mailbox2 = await I.haveNewMailbox();
I.openMailbox(mailbox1);
const email = I.waitForEmailMatching({ subject: 'Register' });
const assert = require('assert');
const mailbox = await I.haveNewMailbox();
const email = await I.waitForEmailMatching({ subject: 'Thanks' });
assert.eql(email.subject, 'Thanks for registering')
MIT
Allows to use real emails in E2E tests via MailSlurp service. Sign up for an account at MailSlurp to start.
A helper requires apiKey from MailSlurp to start
helpers: {
MailSlurp: {
apiKey: '<insert api key here>',
require: '@codeceptjs/mailslurp-helper'
},
}
Use .env file and environment variables to store sensitive data like API keys
apiKey (required) - api key from MailSlurptimeout (default: 10000) - time to wait for emails in milliseconds.debug (default: false) - print debug logsType: {apiKey: string, timeout: number?, debug: boolean?}
Creates a new mailbox. A mailbox will be deleted after a test. Switches to last created mailbox.
const mailbox = await I.haveNewMailbox();
Use an existing mailbox.
const mailbox = await I.haveExistingMailbox('94cxxxf4-7231-46ce-9f40-xxxcae39xxxx');
mailboxId string ID of an existing MailSlurp inbox.Returns Promise<Inbox>
Change a current mailbox to a provided one:
const mailbox1 = await I.haveMailbox();
const mailbox2 = await I.haveMailbox();
// mailbox2 is now default mailbox
// switch back to mailbox1
I.openMailbox(mailbox)
mailboxSends an email from current mailbox, created by I.haveNewMailbox().
I.sendEmail({
to: ['user@site.com'],
subject: 'Hello',
body: 'World'
});
dataWaits for the first email in mailbox. If mailbox is not empty - opens the last email.
I.waitForLatestEmail()
// wait for 30 seconds for an email
I.waitForLatestEmail(30);
sec num? Number of seconds to wait.Returns Promise<Email> an email received.
Wait for an exact email matched by query. You can match emails by from, to, subject, cc, bcc fields.
My default, non-strcit matching enabled, so it searches for inclusion of a string. For a strict matching (equality)
prepend a value with = prefix.
// wait for email with 'password' in subject
const email = await I.waitForEmailMatching({
subject: 'password',
});
// wait 30 seconds for email with exact subject
const email = await I.waitForEmailMatching({
subject: '=Forgot password',
}, 30);
//
const email = await I.waitForEmailMatching({
from: '@mysite.com', // find anything from mysite
subject: 'Restore password', // with Restore password in subject
});
query object to locate an emailsec num? Number of seconds to wait.Returns Promise<Email> an email received.
Wait for exact number of emails in mailbox. Returns the last email in the list.
// wait for 2 emails
I.waitForNthEmail(2);
// wait for 5 emails for 60 seconds
I.waitForNthEmail(5, 60);
// wait for 2 emails and return the last one
const email = await I.waitForNthEmail(2);
numbersecReturns a bunch of emails matched by query.
Similar to waitForEmailMatching but returns an array of emails.
// return 2 emails from 'user@user.com'
const emails = await I.grabEmailsMatching({ from: 'user@user.com'}, 2);
query object to locate an emailnum num? Number of emails to return.Returns Promise<[Email]> emails matching criteria.
Returns all emails from a mailbox.
const emails = await I.grabAllEmailsFromMailbox();
Returns Promise<[Email]> emails.
Checks that current email subject contains a text.
I.seeInEmailSubject('Restore password');
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
textChecks that current email subject does not contain a text.
I.seeInEmailSubject('Restore password');
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
textChecks that current email body contains a text.
I.seeInEmailBody('Click link');
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
textChecks that current email body does not contain a text.
I.dontSeeInEmailBody('Click link');
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
textChecks that email is from a specified address.
I.seeEmailIsFrom('user@user.com');
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
textChecks that current email subject equals to text.
I.seeEmailSubjectEquals('Restore password');
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
textChecks that current email subject doesn't equal to text.
I.dontSeeEmailSubjectEquals('Restore password');
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
textChecks that current email has expected number of attachments.
I.seeNumberOfEmailAttachments(2);
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
numberChecks that current email has an attachment with specified name.
I.seeEmailAttachment('ExampleAttachment.pdf');
Be aware that Mailslurp SDK removes special characters in name of attachment, e.g. "Example-Attachment.pdf" will have name "ExampleAttachment.pdf".
Requires an opened email. Use either waitForEmail* methods to open. Or open manually with I.openEmail() method.
nameRegExpFAQs
MailSlurp helper for testing emails https://mailslurp.com
The npm package @codeceptjs/mailslurp-helper receives a total of 2,598 weekly downloads. As such, @codeceptjs/mailslurp-helper popularity was classified as popular.
We found that @codeceptjs/mailslurp-helper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.