GithubHelp home page GithubHelp logo

nodemailer-mock-transport's Introduction

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);
  });
});

nodemailer-mock-transport's People

Contributors

bcoe avatar greenkeeperio-bot avatar rockbot avatar shaunc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nodemailer-mock-transport's Issues

Add a reset function to reset mocked results

Hi! thanks a lot for this module.
I'm using it to mock email sending from a module in a jasmine test suite. My module uses a config file for configuration purpose, one of these config properties is the nodemailer transport. So, I can't create new mock transports between tests and actually I'm resetting the sentMail array between test, to be sure to check the correct data.

I think it would be great to have an "official" reset function that basically reset all the transport internals (actually only the sentMail array).

What do you think?

mail.data.to can be an array

According to the nodemailer documentation, "to" can be an array of recipients, but npm-user-validate assumes that it is a string.

sendMail callback does not return an info object

Some info object defaults can be determined - better yet, allow the user to determine the response from the callback - including both the err and info objects.

From nodeMail documentation:

info includes the result, the exact format depends on the transport mechanism used
info.messageId most transports should return the final Message-Id value used with this property
info.envelope includes the envelope object for the message
info.accepted is an array returned by SMTP transports (includes recipient addresses that were accepted by the server)
info.rejected is an array returned by SMTP transports (includes recipient addresses that were rejected by the server)
info.pending is an array returned by Direct SMTP transport. Includes recipient addresses that were temporarily rejected together with the server response
info.response is a string returned by SMTP transports and includes the last SMTP response from the server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.