Check if email has been sent to Meteor Velocity

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

I thought I could just have a method in tests with the same name that overrides / duplicates the method, but this does not 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 it always gives me

 Error: A method named 'email' is already defined 
0
source share
1 answer

You can also create an email device 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, as well as clear / receive emails using DDP.

+2
source

Source: https://habr.com/ru/post/986763/


All Articles