我正在尝试使用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: {}
  };
此时我需要在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.js 应用程序编写一些单元测试。我有一些问题,其中之一如下所述:
var sampleFunction = function(){
    var loader = new Loader(params);
    // rest of logic here
}
我想为sampleFunction. 为此,我需要在Loader构造函数上创建 spy并检查此构造函数作为参数获取的内容以及它返回的对象类型。
任何想法如何做到这一点?我尝试创建 spy on ,Loader.prototype.constructor但这不是解决此问题的方法。
我想将茉莉花测试与竹子结合起来,但我不确定是否可能.到目前为止我发现的最好的是https://bitbucket.org/atlassian/bamboo-nodejs-plugin,它只支持mocha测试.我想知道是否有任何方法可以将node-jasmine输出更改为与bamboo兼容.
谢谢
这是jasmine 2.0.0独立项目的一个函数:
function getJasmineRequireObj() {
    if (typeof module !== "undefined" && module.exports) {
        return exports;
    } else {
        window.jasmineRequire = window.jasmineRequire || {};
        return window.jasmineRequire;
    }
}
我想如果我使用标准的require方法,将定义module属性.当我使用VM模块加载此文件时,如下所示模块全局属性是未定义的:
var fs = require('fs');
var vm = require('vm');
var jasmineFile = fs.readFileSync(__dirname + '/jasmine.js');
vm.runInThisContext(src, jasmineFile);
这是VM模块的预期行为还是缺陷?
使用这个安装的jasmine-node:
sudo npm install jasmine-node -g
它成功并显示:
/usr/bin/jasmine-node -> /usr/lib/node_modules/jasmine-node/bin/jasmine-node
jasmine-node@1.14.3 /usr/lib/node_modules/jasmine-node
??? underscore@1.6.0
??? mkdirp@0.3.5
??? walkdir@0.0.7
??? jasmine-reporters@2.0.0
??? coffee-script@1.7.1
??? requirejs@2.1.14
??? jasmine-growl-reporter@0.0.3 (growl@1.7.0)
??? gaze@0.3.4 (minimatch@0.2.14, fileset@0.1.5)
但是当我尝试运行它时:$ jasmine-node spec/或者jasmine-node它显示如下错误:
/usr/lib/node_modules/jasmine-node/lib/jasmine-node/reporter.js:336
  jasmineNode.TeamcityReporter.prototype = new jasmine.TeamcityReporter;
                                           ^
TypeError: undefined is not a function
    at /usr/lib/node_modules/jasmine-node/lib/jasmine-node/reporter.js:336:44
    at Object.<anonymous> (/usr/lib/node_modules/jasmine-node/lib/jasmine-node/reporter.js:342:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/lib/node_modules/jasmine-node/lib/jasmine-node/index.js:34:21)
    at Module._compile (module.js:456:26)
我正在尝试从 Windows cmd 运行 jasmine-node,但没有成功。我的 package.json 在我项目的顶层,有以下内容
{
    "devDependencies": {
    "jasmine-node": ""
    }
}
我在项目的顶层运行它。
npm install
然后这个
node_modules/jasmine-node/bin/jasmine-node spec/greetSpec.js
这是结果
'node_modules' is not recognized as an internal or external command,
operable program or batch file.
安装 jasmin-node 出了什么问题?在 Windows 中执行此操作的正确方法是什么?
我有一个函数,抛出我正在测试的错误.这是功能:
parse: function(input) {
        var results = {};       
        var that = this;
        input.forEach(function(dependency) {
            var split = dependency.split(": ");
            var lib = split[0];
            var depen = split[1];       
            if(depen === undefined) {
                throw new Error('Invalid input. Requires a space after each colon.')
            }
            results[lib] = depen;
        });
        return results;
    }
当我测试这个函数时,我点击错误代码并想要验证是否抛出了错误.这是我的测试代码:
var invalidInput = ['Service1: ', 'Service2:stuff'] 
expect(manager.parse(invalidInput)).toThrowError();
但我的测试失败了.这是我的堆栈跟踪:
Failures:
  1) dependency.js input should require a space after each colon as specified by requirements
   Message:
     Error: Invalid input. Requires a space …为什么以下代码会因超时而失败?看起来“应该”抛出错误并且 done() 永远不会被调用?如何编写此测试以使其正确失败而不是让 jasmine 报告超时?
var Promise = require('bluebird');
var should = require('chai').should();
describe('test', function () {
  it('should work', function (done) {
    Promise.resolve(3)
      .then(function (num) {
        num.should.equal(4);
        done();
      });
  });
});
控制台输出是:
c:>茉莉花节点规范\
未处理的拒绝 AssertionError:预期 3 等于 4 ...失败:1)测试应该工作消息:超时:等待规范完成 5000 毫秒后超时
我了解到这种方式是在describe()中循环遍历it()的最佳方式,但是在"spec not found"的情况下它失败了,并且似乎在for循环函数之前就停止了,我想知道我在哪里做错误?
谢谢!
describe('this is my looping test!', function() {
  var input = [1,2,3];
  var output = [10, 20, 30];
  function test_my_times_ten(input, output) {
    it('should multiply ' + input + ' by 10 to give ' + output, function() {
      expect(input * 10).toEqual(output)
    });
  }
  for(var x = 0; x < input.size; x++) {
    test_my_times_ten(input[x], output[x]);
  }
});
现在我的团队正在运行量角器/茉莉花节点进行验收测试,并使用karma/jasmine进行单元测试.
有可能,并且它已经发生了,有人用iit或代码进行量角器/茉莉花节点测试推送代码,并适合或描述业力/茉莉花测试.这样做会强制茉莉只运行那些测试,跳过所有其他测试.这对于调试很有用,但是如果有人忘记恢复这些更改并将此代码推送到我们的持续集成服务器(Jenkins),我希望我们的CI作业失败,因为可能存在被跳过的破坏的测试.
是否有任何命令行标志或配置设置我可以传递给karma.conf.js或protractor.conf.js,这将强制所有测试运行,以便我们的CI框不会跳过任何测试?
我猜这个问题是两个部分,对于业力/茉莉和量角器/茉莉节点.任何帮助表示赞赏.
我的版本:
"jasmine-core": "^2.3.4",
"karma": "~0.12",
"karma-jasmine": "^0.3.5",
"protractor": "^2.1.0",
"jasmine-node": "~1.14.5",
jasmine-node ×10
node.js ×7
jasmine ×6
javascript ×3
unit-testing ×3
bamboo ×1
meteor ×1
protractor ×1
spy ×1