测试电子邮件是否以 Meteor Velocity 发送
Test if email is send in Meteor Velocity
是否可以在 Meteor Velocity 测试中确认正在发送电子邮件?
我想我可以在 tests
中使用与 override/duplicates 方法同名的方法,但这不起作用。我试过这个:
在我的常规代码中:
Meteor.methods(
email: (parameters) ->
sendAnEmail(parameters)
)
在tests
中:
Meteor.methods(
email: (parameters) ->
differentBehaviorForTesting(parameters)
# I could call some super() here if necessary
)
但这总能让我得到一个
Error: A method named 'email' is already defined
您还可以创建如下所示的电子邮件装置:
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({});
}
这将允许您正常发送电子邮件,并使用 DDP 清除/获取电子邮件。
是否可以在 Meteor Velocity 测试中确认正在发送电子邮件?
我想我可以在 tests
中使用与 override/duplicates 方法同名的方法,但这不起作用。我试过这个:
在我的常规代码中:
Meteor.methods(
email: (parameters) ->
sendAnEmail(parameters)
)
在tests
中:
Meteor.methods(
email: (parameters) ->
differentBehaviorForTesting(parameters)
# I could call some super() here if necessary
)
但这总能让我得到一个
Error: A method named 'email' is already defined
您还可以创建如下所示的电子邮件装置:
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({});
}
这将允许您正常发送电子邮件,并使用 DDP 清除/获取电子邮件。