如何使用 jest 测试 Meteor.methods 中的区块

How to use jest to test blocks in Meteor.methods

我正在为我的流星项目编写笑话测试。我正在尝试测试 Meteor.methods 中的代码,但我不确定如何使用 Jest 进行测试。

在服务器端(也是 main.js),代码片段如下所示,

Meteor.methods({
        'shops.get': () => { return ShopList.find({}).fetch();},
)};

在main.test.js,我写了类似

的东西
describe('methods', () => {
    let shops=[];
    beforeEach(() => {
    Meteor.call('shops.get',(e,r)=>{
      if(!e) shops=r;
    });
 });
});

但是出现错误:

    ReferenceError: Meteor is not defined

我读过一篇文章提到在文件中伪造流星。(https://blog.meteor.com/real-world-unit-tests-with-meteor-and-jest-3d557e84e84a),但我不确定如何以这种方式解析 Meteor.call 或 [=27= 等符号].

欢迎任何想法。

查看 https://guide.meteor.com/testing.html 了解有关测试的信息。

这是一个集成测试,因为你正在测试数据库功能,你应该使用 Meteor 来 运行 测试,否则你有很多模拟要做,然后你就证明不了多少除了你的模拟按预期工作。

所以使用 meteor test 命令,使用适当的驱动程序,例如 https://atmospherejs.com/meteortesting/mocha - 这不是开玩笑,但它会给你想要的结果。

如果您需要更多信息,我可以为您提供一些示例代码。