nodemailer-mock-transport

1.3.0 • Public • Published

nodemailer-mock-transport

Build Status Coverage Status

Mock nodemailer-transport, for testing services that rely on nodemailer.

describe('mock-transport', function() {
  it('should store configuration options so that they can be asserted against', function() {
    var transport = mockTransport({
      foo: 'bar'
    });
    transport.options.foo.should.equal('bar');
  });
 
  it('should store emails sent with nodemailer, so that they can be asserted against', function() {
    var transport = mockTransport({
      foo: 'bar'
    });
 
    var transporter = nodemailer.createTransport(transport);
 
    transporter.sendMail({
      from: 'sender@address',
      to: 'receiver@address',
      subject: 'hello',
      text: 'hello world!'
    });
 
    transport.sentMail.length.should.equal(1);
    transport.sentMail[0].data.to.should.equal('receiver@address');
    transport.sentMail[0].message.content.should.equal('hello world!');
  });
 
  it('should return an error and not send an email if there is no `to` in the mail data object', function () {
    var transport = mockTransport({
      foo: 'bar'
    });
 
    var transporter = nodemailer.createTransport(transport);
 
    transporter.sendMail({
      from: 'sender@address',
      subject: 'hello',
      text: 'hello world!'
    });
 
    transport.sentMail.length.should.equal(0);
  });
});

Readme

Keywords

Package Sidebar

Install

npm i nodemailer-mock-transport

Weekly Downloads

1,542

Version

1.3.0

License

ISC

Last publish

Collaborators

  • rockbot
  • bcoe