Tag: 茉莉

业力开始找不到模块'jasmine-core'

当我运行“业力开始”时,我得到以下错误: module.js:340抛出err; ^错误:在init.asmine(/ usr / lib / node_modules)的Function.require.resolve(module.js:384:19)处的Function.Module._resolveFilename(module.js:338:15)处找不到模块'jasmine-core' /karma-jasmine/lib/index.js:8:42)Array.invoke [as 0](/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)at get( /usr/lib/node_modules/karma/node_modules/di/lib/injector.js:48:43)在/usr/lib/node_modules/karma/lib/server.js:137:20 Array.forEach(native)at Server._start(/usr/lib/node_modules/karma/lib/server.js:136:21)在调用(/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)at Server.start(/usr/lib/node_modules/karma/lib/server.js:101:18)在Object.exports.run(/usr/lib/node_modules/karma/lib/cli.js:231:26)at目的。 (module.js:474:10)在Module._compile(module.js:456:26)处的/ usr / lib / node_modules / karma / bin / Module.load(module.js:356:32)在Function.Module._load(module.js:312:12) 有谁知道这是为什么发生? 我在虚拟机中运行业力。 我尝试了几个npm安装命令,没有任何工作。 在我关机后的第二天,问题就消失了,一切都恢复正常了。 所以,我不再被阻止..任何人都有可能发生什么想法?

是否有可能使用Jasmine的hasBeenCalledWith具有正则expression式的匹配器?

我已经检查了Jasper的toHaveBeenCalledWith匹配器的文档,以了解是否有可能为parameter passing一个正则expression式,如果该参数预期是一个string的话。 不幸的是,这是不受支持的function。 github上还有一个问题需要这个function。 我已经挖掘了一些代码库,并且看到如何在现有的匹配器中实现这个function。 我认为将它作为一个单独的匹配器来实现会更合适,因此抽象是单独捕获的。 与此同时,什么可能是一个很好的解决方法?

使用Jasmine监听构造函数

我正在使用Jasmine来testing是否创build了某些对象,并调用方法。 我有一个jQuery小部件,创buildflipcounter对象,并调用setValue方法。 flipcounter的代码在这里: https ://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js flipcounters创build使用: var myFlipCounter = new flipCounter("counter", {inc: 23, pace: 500}); 我想testingflipcounters是否被创build,并调用setValue方法。 我的问题是,如何在这些对象被创build之前监视它们? 我是否监视构造函数并返回假对象? 示例代码真的有帮助。 谢谢你的帮助! 🙂 更新: 我试过这样的flipCounter间谍: myStub = jasmine.createSpy('myStub'); spyOn(window, 'flipCounter').andReturn(myStub); //expectation expect(window.flipCounter).toHaveBeenCalled(); 然后通过flipCountertestingsetValue调用: spyOn(myStub, 'setValue'); //expectation expect(myStub.setValue).toHaveBeenCalled(); 初始化flipCounter的第一个testing是好的,但为了testingsetValue调用,所有我得到的是一个'setValue()方法不存在'的错误。 我是这样做的吗? 谢谢!

茉莉花 – 在构造函数中侦听方法调用

我想testing是否在我的Javascript对象构造函数中调用以下方法。 从我在Jasmine文档中看到的,我可以窥探一个构造函数方法,并且可以在一个对象被实例化之后监听方法,但是我似乎无法在构造对象之前窥探一个方法。 物体: Klass = function() { this.called_method(); }; Klass.prototype.called_method = function() { //method to be called in the constructor. } 我想在规范中做这样的事情: it('should spy on a method call within the constructor', function() { spyOn(window, 'Klass'); var obj = new Klass(); expect(window.Klass.called_method).toHaveBeenCalled(); });

嘲笑Jasmineunit testing中的Angular模块依赖关系

我试图unit testing控制器代码在一个模块,其他模块作为依赖,但一直没能弄清楚如何正确地嘲笑他们。 我正在使用茉莉花框架,并运行与噶(测量)的testing。 模块代码 var app = angular.module('events', ['af.widgets', 'angular-table']); app.controller('eventsCtrl', function([dependencies]){ $scope.events = []; … }); 规范代码 describe('events module', function(){ var $scope, ctrl; beforeEach(function(){ angular.mock.module('af.widgets', []); angular.mock.module('angular-table', []); module('events', ['af.widgets', 'angular-table']); }); beforeEach(inject(function($rootScope, $controller){ $scope = $rootScope.new(); ctrl = $controller('NameCtrl', { $scope: $scope, }); })); it('should have an empty events array', function(){ expect($scope.events).toBe([]); }) […]

茉莉花与摩卡JavaScripttesting的Rails 3.1 +

我有茉莉花的经验,并做了相当多的。 有没有人有茉莉花和摩卡,专门为Rails的经验? 我想知道是否值得转换。

如何访问和testingnode.js模块中的内部(非导出)函数?

我试图找出如何testing内部(即不导出)的function在nodejs(最好与摩卡或茉莉花)。 而我不知道! 假设我有一个这样的模块: function exported(i) { return notExported(i) + 1; } function notExported(i) { return i*2; } exports.exported = exported; 而下面的testing(摩卡): var assert = require('assert'), test = require('../modules/core/test'); describe('test', function(){ describe('#exported(i)', function(){ it('should return (i*2)+1 for any given i', function(){ assert.equal(3, test.exported(1)); assert.equal(5, test.exported(2)); }); }); }); 有没有办法unit testingnotExported函数,而不实际导出它,因为它不是要被暴露?

我怎样才能让WebStorm识别茉莉花的方法?

我有一个node.js项目,其中包含一些茉莉花规格。 规范是在spec /子目录中,并具有.spec.coffee扩展,如茉莉花节点所要求的。 当我在WebStorm IDE中打开其中一个规格文件时,所有对beforeEach和describe的调用beforeEach显示蓝色的波形下划线,工具提示“Unresolved function or method it()”。 所以,即使我使用3.0 EAP ,它应该有一些茉莉花支持 ,它不会自动采取事实,这是一个茉莉花规格文件。 我尝试进入文件>设置> JavaScript库,并添加Jasmine作为库(指定茉莉花2.0.0.rc1.js的path),然后进入使用范围子页面,并检查“茉莉花”在“项目”旁边的下拉列表,但没有任何效果 – 茉莉花的方法仍然显示为未解决。 我怎么能告诉WebStorm spec子目录中的所有文件和/或扩展名为.spec.coffee的所有文件都是Jasminetesting,并且能够识别那些testing正在使用的Jasmine API?

我如何关注jasmine.js中的一个规范?

我从一个相当大的体系结构变化中获得了一堆失败的规范。 我想通过用“焦点”标记每一个来逐一修复它们。 jasmine.js有这样的function吗? 我发誓我曾经读过,但是我没有在文档中看到它。