ts-smtp-test
v1.0.8
Published
smtp server for integration testing
Downloads
72
Readme
ts-smtp-test
SMTP server for integration tests.
Uses https://nodemailer.com/ as SMTP-Server.
const server = new SmtpTestServer();
before(async () => {
await server.start();
});
beforeEach(() => {
server.clear();
});
after(async () => {
await server.shutdown();
});
it("can receive mail", async () => {
await sendMail(server.config, {
attachments: [{content: "text attachment"}],
from: "[email protected]",
html: "some html",
subject: "hi",
text: "some text",
to: "[email protected]",
});
expect(server.messages).length(1);
const mail = server.messages[0];
expect(mail.from).to.eq("[email protected]");
expect(mail.to).to.eq("[email protected]");
expect(mail.subject).to.eq("hi");
expect(mail.textContent).to.eq("some text");
expect(mail.htmlContent).to.eq("some html");
expect(mail.attachments).length(1);
});
it("can wait for mails", async () => {
setTimeout(() =>
sendMail(server.config, {
text: "1",
to: "[email protected]",
},
).catch(console.error), 5);
setTimeout(() =>
sendMail(server.config, {
text: "2",
to: "[email protected]",
},
).catch(console.error), 10);
// wait for 2 messages with a timeout of 15 millis
const messages = await server.waitForMessages(2, 15);
expect(messages).length(2);
expect(messages[0].textContent).to.contain("1");
expect(messages[1].textContent).to.contain("2");
});
Previous versions
Source: https://bitbucket.org/martinmo/ts-tools