1
我試圖測試我的軟件包,它需要的值是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);
});
},
});
haver你試過像'流星測試--settings your.settings.file.json'嗎? – Samuel