如何使用玩笑来测试Meteor.method中的块

时间:2019-05-23 09:16:39

标签: javascript meteor jestjs ts-jest

我正在为流星项目编写笑话测试。我正在尝试在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或Meteor.methods之类的符号。

任何想法都值得赞赏。

1 个答案:

答案 0 :(得分:0)

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

这是一个集成测试,当您测试数据库功能时,应该使用Meteor来运行测试,否则您需要进行很多模拟,然后除了证明模拟可以正常工作之外,您不需要证明太多

因此,请使用meteor test命令以及适当的驱动程序,例如https://atmospherejs.com/meteortesting/mocha-这不是开玩笑,但它会为您提供所需的结果。

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

相关问题