茉莉花节点 – 包括帮手

我试图用茉莉花节点来testing我的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: {} }; 

在这一点上,我需要在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(); }); }); }); 

任何帮助将不胜感激。

jasmine_node会从您的spec目录中自动加载助手(任何包含helpers字样的文件)。

注意:你可以欺骗和使用helper因为它是helpers的一个子string…更有意义的是,如果你将帮助者分成多个文件…单数对复数。

如果你从specs/unit执行你的规格,然后创build一个名为specs/unit/meteor-helper.jsjasmine_node会自动为你find它。 如果您的规范是用vanilla JavaScript编写的,它将加载扩展名为.js文件。 如果你通过命令行上的--coffee开关或者通过你的grunt任务configuration(如果你有雄心壮志,你甚至可以使用gulp),那么它会使用扩展js|coffee|litcoffee加载助手。

你应该从每个帮助文件中导出一个hash ,如下所示:

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: {} }

然后, jasmine_node将每个键写入 全局名称空间 。

这将允许你简单地从你的规格或任何被testing的系统(通常是你的lib文件夹中的规范正在执行断言的代码)键入keyMeteor

另外, jasmine_node还允许你通过--nohelpers开关来禁止helpers的加载(更多细节见code或README )。

这是通过节点处理茉莉花助手的正确方法。 你可能会遇到一些参考jasmine.yml文件的答案/例子; 甚至可能是spec_helper.js 。 但请记住, 这是ruby土地,而不是节点。

更新:它显示jasmine-node将只会源文件,如果它包含单词helpers 。 命名每个助手文件x-helper.js|coffee|litcofee应该做的伎俩。 即meteor-helper.coffee