ale*_*333 4 node.js jasmine meteor jasmine-node
我正在尝试使用jasmine-node测试我的Meteor应用程序.我已经在帮助器(spec_helper.js)中删除了一些Meteor框架的方法:
var Meteor = {
startup: function (newStartupFunction) {
Meteor.startup = newStartupFunction;
},
Collection: function (collectionName) {
Meteor.instantiationCounts[collectionName] = Meteor.instantiationCounts[collectionName] ?
Meteor.instantiationCounts[collectionName] + 1 : 1;
},
instantiationCounts: {}
};
Run Code Online (Sandbox Code Playgroud)
此时我需要在spec_helper.js中运行代码(相当于在其他语言中包含一个模块).我尝试了以下,但没有成功:
require(['spec_helper'], function (helper) {
console.log(helper); // undefined
describe('Testing', function () {
it('should test Meteor', function () {
// that's what I want to call from my stubs...
// ...it's obviously undefined
Meteor.startup();
});
});
});
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
jasmine_node将从helpersspec目录中自动加载帮助程序(包含该单词的任何文件).
注意:你可以作弊和使用,helper因为它是helpers... 的子串更有意义,如果你在多个文件中分离助手...单数与复数.
如果您正在执行您的规范specs/unit,则创建一个名为的文件specs/unit/meteor-helper.js,并jasmine_node自动为您提供源文件..js如果您的规范是用vanilla JavaScript编写的,它将加载带扩展名的文件.如果您通过命令行或通过grunt任务配置传递--coffee开关(如果您雄心勃勃,甚至可能使用gulp),那么它将加载带有扩展的助手js|coffee|litcoffee.
您应该hash从每个帮助文件导出a ,如下所示:
specs/unit/meteor-helper.js
// file name must contain the word helper
// x-helper is the convention I roll with
module.exports = {
key: 'value',
Meteor: {}
}
这将允许您只需键入key或Meteor从您的规范或任何被测系统(通常是您的lib文件夹中的规范正在执行断言的代码).
此外,jasmine_node还允许您通过--nohelpers交换机抑制帮助程序的加载(有关详细信息,请参阅代码或自述文件).
这是通过节点处理jasmine帮助程序的正确方法.您可能会遇到一些引用jasmine.yml文件的答案/示例; 或者甚至是spec_helper.js.但请记住,这是红宝石的土地,而不是节点.
更新:jasmine-node如果文件包含单词,它似乎只会来源helpers.命名每个帮助文件x-helper.js|coffee|litcofee应该可以解决问题.即meteor-helper.coffee.
| 归档时间: |
|
| 查看次数: |
5325 次 |
| 最近记录: |