【发布时间】:2015-03-02 11:10:16
【问题描述】:
我尝试在 RubyMine 中使用 Jasmine 测试我的 AngularJS 控制器。
这是我的测试
'使用严格';
describe('MainCtrl', function(){ var scope;
beforeEach(module('myModule'));
beforeEach(注入(函数($rootScope) { 范围 = $rootScope.$new(); }));
it('应该定义超过 5 个很棒的东西', 注入(函数($控制器){ 期望(scope.awesomeThings).toBeUndefined();
$controller('MainCtrl', { $scope: scope }); expect(angular.isArray(scope.awesomeThings)).toBeTruthy(); expect(scope.awesomeThings.length > 5).toBeTruthy(); })); });
我使用 Karma 来运行这个测试。为了配置 RubyMine 来运行测试,我做了所有这些教程中写的操作 https://www.jetbrains.com/ruby/webhelp/preparing-to-use-karma-test-runner.html https://www.jetbrains.com/ruby/webhelp/running-unit-tests-on-karma.html
这是我的 Karma 配置文件
'使用严格';
module.exports = 功能(配置){
config.set({ 自动监视:假,
frameworks: ['jasmine'], browsers : ['PhantomJS'], plugins : [ 'karma-phantomjs-launcher', 'karma-jasmine' ] }); };
但是当我尝试运行测试时出现此错误
src/app/main/main.controller.spec.js:3 describe('MainCtrl', function(){ ^ ReferenceError: describe is not defined
at Object.<anonymous> (src/app/main/main.controller.spec.js:3:1) 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 Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:929:3
我该如何解决这个问题?我很乐意为您提供任何帮助。
【问题讨论】:
-
您是使用 Karma 运行器还是节点运行器运行测试?
-
我以为我用的是 Karma runner,但实际上它是 node runner。傻我!但是我现在遇到了一个问题,因为 Karma runner 没有找到我的测试并且我得到“空测试套件”
标签: angularjs karma-runner rubymine karma-jasmine