我正在尝试测试需要Meteor.settings
值的包。但是当我开始测试时,我收到了这个错误:
Exception while invoking method 'sendData' TypeError: Cannot read property 'appKey' of undefined
我的测试:
it('sends event data in proper form', function () {
Meteor.settings = {
myApp: {
appKey: 'thisisafakeappkey',
},
};
const post = sinon.stub(HTTP, 'post');
trackEvent(event, data, user);
HTTP.post.restore();
}
方法:
Meteor.methods({
'sendData'({ payload }) {
const appKey = Meteor.settings.myapp.appKey;
if (!appKey) throw new Meteor.Error('No app key found in Meteor.settings.');
const withAppKey = Object.assign({ appKey }, payload);
HTTP.post(getRemoteUrl(), {
data: withAppKey,
}, (err, res) => {
if (err) console.log('err', err);
else console.log('res', res);
});
},
});
答案 0 :(得分:2)
如果您使用meteor 1.3,您至少可以使用以下命令运行完整的应用测试:
meteor test --full-app --settings my.settings.json --driver-package <driverpackage>