【问题标题】:Testing in Meteor在 Meteor 中测试
【发布时间】:2017-11-21 10:33:04
【问题描述】:

我正在尝试在 Meteor 中添加测试。我在“imports”文件夹中添加了我的测试。这是测试文件:

import { Meteor } from 'meteor/meteor';
import { chai } from 'meteor/practicalmeteor:chai';

if (Meteor.isClient) {
  describe('Client Tasks', () => {
    describe('methods', () => {
      it('can delete owned task', () => {
        Meteor.call('getVideoData', function (error, res) {
          if (error) console.log('error', error)
          console.log('ok', res);
        })
      });
    });
  });
}

我尝试调用一个方法并记录结果,但出现以下错误:

路径没有路由:/

控制台日志的结果是:

错误 {"isClientSafe":true,"error":404,"reason":"方法 'getVideoData' 未找到","message":"方法 'getVideoData' 未找到 [404]","errorType": “流星.错误”}

好的未定义

我用 Meteor 做后端,用 React 做前端。

我是在测试文件中遗漏了某些内容还是与其他内容有关?

这是回购链接github

【问题讨论】:

    标签: reactjs testing meteor


    【解决方案1】:

    您看到的直接问题是"Method 'getVideoData' not found"。那是因为运行meteor test 只会加载您专门拥有imported 的模块。 It does not eagerly load your project 就像我们在本地开发模式下为流星服务时所习惯的那样。您只将 Meteorchai 导入到此测试中,因此测试对您在项目的其他文件中编写的任何方法一无所知。

    但是,这导致了一个更根本的问题,因为meteor test 无论如何都不会运行前端和后端,因此在测试前端时,方法不能作为从服务器检索数据的方法进行测试。相反,在测试前端时,您需要存根/模拟对Meteor.call('getVideoData') 的调用,而您真正能做的就是断言它已被调用并提供您自己的假返回数据,如in this example 所示。

    然后您需要编写单独的后端测试来验证方法(并希望它调用的分隔函数)正确地检索正确的数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 2018-07-09
      • 2013-02-17
      • 1970-01-01
      相关资源
      最近更新 更多