Test if email is send in Meteor Velocity

試著忘記壹切 提交于 2020-01-25 20:58:45

问题


Is it possible to confirm emails are being sent in Meteor Velocity tests?

I thought I could just have a method in tests with the same name that override/duplicates the method, but that doesn't work. I tried this:

In my regular code:

Meteor.methods(
   email: (parameters) ->
      sendAnEmail(parameters)
)

In tests:

Meteor.methods(
   email: (parameters) ->
      differentBehaviorForTesting(parameters)
      # I could call some super() here if necessary
)

But this always gets me a

Error: A method named 'email' is already defined

回答1:


You can also create an email fixture that looks something like this:

  var _fakeInboxCollection = new Package['mongo'].Mongo.Collection('Emails');

  Meteor.startup(function () {
    _clearState();
    _initFakeInbox();
  });

  Meteor.methods({
    'clearState': _clearState,
    'getEmailsFromInboxStub': function () {
      return _fakeInboxCollection.find().fetch()
    }
  });

  function _initFakeInbox () {
    _fakeInboxCollection.remove({});
    Email.send = function (options) {
      _fakeInboxCollection.insert(options);
    };
  }

  function _clearState () {
    _fakeInboxCollection.remove({});
  }

This will allow you to send emails normally and also clear / fetch the emails using DDP.



来源:https://stackoverflow.com/questions/30080348/test-if-email-is-send-in-meteor-velocity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!