【问题标题】:Accessing Meteor settings in Mocha在 Mocha 中访问 Meteor 设置
【发布时间】:2017-09-27 09:00:59
【问题描述】:

我想用 mocha 编写一些单元测试,但对于一些测试,我需要访问流星从文件中读取的 Meteor.settingsconfig/settings.json

通常我通过以下方式导入流星:

import { Meteor } from 'meteor/meteor'

但是当我尝试在我的测试中导入它时,我得到了错误:ERROR: Cannot find module 'meteor/meteor'(我也尝试过做相对路径)。

我通过这个来运行我的测试:

"wdio-test": "wdio tests/config/wdio.mocha.conf.js"

npm run wdio-test

任何人都可以帮助导入 Meteor 或访问设置文件(如果可能没有文件 IO 操作)?

【问题讨论】:

  • 如何运行测试?
  • 我把执行命令和脚本放在我的问题里
  • 那样不行,wdio 真的不知道meteor/meteor 是什么意思。它仅在带有 babel-* 转译器和转换的流星内部工作。我建议你使用meteor testing
  • 呃,这很糟糕,因为,我怎样才能使用与 webdriverio 相关的东西,比如无头浏览器?
  • 好吧,如果您使用测试来测试与流星相关的东西,也许使用专门为此设计的流星包会更好?看看我提供的链接,也许你会发现它更适合你。

标签: node.js meteor mocha.js


【解决方案1】:

存根流星核心和设置对象:

import { MeteorStubs } from 'meteor/velocity:meteor-stubs';

describe('tests', function() {
  beforeEach(function() {
    MeteorStubs.install();
    Meteor.settings.public.foo = 'bar';
  });
  afterEach(function() {
    MeteorStubs.uninstall();
  });
  it('gets setting', function() {
    chai.assert.equal(Meteor.settings.public.foo, 'bar');
  });

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-29
    • 2012-12-29
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多