AngularJS业力 - 无法启动单元测试

时间:2015-05-13 04:34:23

标签: angularjs unit-testing karma-jasmine

我正在尝试为角度控制器编写样本单元测试。但是测试失败并显示错误消息:

  Error: Unknown provider: $$rAFProvider from ngMock
        at Error (native)
        at c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular.min.js:28:338
        at Object.c [as get] (c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular.min.js:26:104)
        at Object.j.$provide.decorator (c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular.min.js:28:217)
        at c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular-mocks.js:1746:12
        at Object.d [as invoke] (c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular.min.js:26:320)
        at c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular.min.js:25:107
        at Array.forEach (native)
        at m (c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular.min.js:6:193)
        at e (c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/vendor/angularjs/angular.min.js:24:398)
    TypeError: Cannot read property 'testName' of undefined
        at null.<anonymous> (c:/eclipse/workspace/Ecomm-Fron-End/WebContent/js/assets/test/sample.js:18:18)

我的示例测试用例是:

describe('Unit: homeCtrl', function() {
  // Load the module with MainController
  beforeEach(module('yourMarketApp'));

   var ctrl, scope;

  beforeEach(inject(function($controller, $rootScope) {
    // Create a new scope that's a child of the $rootScope
    scope = $rootScope.$new();
    // Create the controller
    ctrl = $controller('homeCtrl', {
      $scope: scope
    });
  }));

   it('should test scope.testName', 
    function() {
        expect(scope.testName).toEqual("");
  });

});

我已经检查过,角度和角度模拟文件版本相同(v1.2.19)

0 个答案:

没有答案