Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用Karma和Jasmine在运行单元测试用例时执行0/0错误_Angularjs_Unit Testing_Jasmine_Requirejs_Karma Jasmine - Fatal编程技术网

Angularjs 使用Karma和Jasmine在运行单元测试用例时执行0/0错误

Angularjs 使用Karma和Jasmine在运行单元测试用例时执行0/0错误,angularjs,unit-testing,jasmine,requirejs,karma-jasmine,Angularjs,Unit Testing,Jasmine,Requirejs,Karma Jasmine,我想使用karma和jasmine运行测试用例。我已经做了以下操作,但它给出了如下错误: 错误: Chrome 59.0.3071 (Linux 0.0.0): Executed 0 of 0 ERROR (0.12 secs / 0 secs) karma.conf.js: module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine','requirejs'],

我想使用
karma
jasmine
运行测试用例。我已经做了以下操作,但它给出了如下错误:

错误:

Chrome 59.0.3071 (Linux 0.0.0): Executed 0 of 0 ERROR (0.12 secs / 0 secs)
karma.conf.js:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine','requirejs'],
    files: [
        {pattern: 'node_modules/**/*.js', included: false}, 
        //source files
        {pattern: 'src/**/*.js', included: false}, 
        //test files
        {pattern: 'tests/**/apptest-spec.js', included: false}, 

        'tests/test-main.js' 
     ],
    exclude: [
    ],
    plugins: [
        'karma-requirejs',
        'karma-chrome-launcher',
        'karma-jasmine'
    ],
    preprocessors: {
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
}
apptest-spec.js:

describe('MainCtrl', function() {
  beforeEach(module('app-module'));
  var $controller;
  beforeEach(inject(function(_$controller_){
    $controller = _$controller_; 
    }));

  describe('$scope.titleofapp', function() {
    var $scope, controller;
    beforeEach(function() {
      $scope = {};
      controller = $controller('MainCtrl', { $scope: $scope });
    });

    it('sets the title of app to "TestApp" module', function() {
      $scope.titleofapp();
      expect($scope.title).toEqual('TestApp');
    });
  });
});
MainCtrl.js:

define(['angular', './app-module'], function(angular, appModule) {
    'use strict';
    return appModule.controller('MainCtrl', ['$http', '$q', 'appService', '$stateParams', function($http, $q, $stateParams, appService){
        $scope.titleofapp = function(){
        $scope.title = 'TestApp';
        }
   }]);  
});
test-main.js:

var allTestFiles = [];
var TEST_REGEXP = /(-orchestratespec).js/;
Object.keys(window.__karma__.files).forEach(function(file) {
        if (TEST_REGEXP.test(file)) {
        var normalizedTestModule = file;
        console.log('normalized path', normalizedTestModule);// giving: '/base/tests/controllers/apptest-spec.js'
        allTestFiles.push(file);
    }
});
console.log(allTestFiles);// giving: ['/base/tests/controllers/apptest-spec.js']
require.config({
     baseUrl: '/base/tests/scripts',
    paths: {
        node_modules: '/base/node_modules',      
    },
    deps: allTestFiles,  
    callback: window.__karma__.start()
});
我不确定我哪里做错了,请帮助我成功运行我的测试用例。提前谢谢


注意:如果我在浏览器中重新加载应用程序,我可以在“网络”选项卡中看到,状态为“取消”,url名称如下:

如果进入Karma启动的浏览器,进入“调试”面板,执行页面重新加载并查看网络活动,是否有对
../apptest-spec.js的请求,并且成功了吗?@Louis,是的,我在上面做了,通过观察重新加载,它在网络选项卡中给出:,状态被取消。我想这是因为
回调:窗口。
karma_uuuu.start()应该是
回调:窗口。
karma_uu.start
(在
require.config({…})中)
test main.js
)@xmike中,如果我在test-main.js中为callback:,编写上面的语句,那么它会给出错误,比如:Uncaught SyntaxError:Unexpected token in。好吧,这意味着在某个地方有语法错误)确切的位置在哪里?上面说什么?顺便说一句,如果你在
karma.conf.js
中切换到
config.LOG\u DEBUG
设置所有环境,这可能会更好,有时会很有帮助。如果你进入karma启动的浏览器,进入调试面板,重新加载页面并查看网络活动,是否有对
../apptest-spec.js的请求,并且成功了吗?@Louis,是的,我在上面做了,通过观察重新加载,它在网络选项卡中给出:,状态被取消。我想这是因为
回调:窗口。
karma_uuuu.start()应该是
回调:窗口。
karma_uu.start
(在
require.config({…})中)
test main.js
)@xmike中,如果我在test-main.js中为callback:,编写上面的语句,那么它会给出错误,比如:Uncaught SyntaxError:Unexpected token in。好吧,这意味着在某个地方有语法错误)确切的位置在哪里?上面说什么?顺便说一句,如果您在
karma.conf.js
中切换到
config.LOG\u DEBUG
可能会更好,因为在设置所有环境的过程中,它有时会有所帮助。