问题
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