在Mocha中访问Meteor设置
我想用mocha编写一些单元测试但是对于一些测试我需要访问Meteor.settings
,它们是由文件中的meteor读取的:config/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操作)?
回答如下:存储流星核心和设置对象:
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');
});
});
在Mocha中访问Meteor设置
我想用mocha编写一些单元测试但是对于一些测试我需要访问Meteor.settings
,它们是由文件中的meteor读取的:config/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操作)?
回答如下:存储流星核心和设置对象:
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');
});
});