gpt4 book ai didi

unit-testing - 测试依赖于 Meteor 设置的包

转载 作者:行者123 更新时间:2023-11-28 19:57:53 25 4
gpt4 key购买 nike

我正在尝试测试我的包,它需要来自 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);
});
},
});

最佳答案

如果您使用 meteor 1.3,您至少可以运行完整的应用测试:

meteor test --full-app --settings my.settings.json --driver-package <driverpackage>

https://guide.meteor.com/testing.html

关于unit-testing - 测试依赖于 Meteor 设置的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38252168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com