2016-06-07 49 views
3

我正在我的測試與人緣和幻影,我也正在使用摩卡和興農和考驗越來越失敗,以下錯誤:「之前每一個」鉤:workFn錯誤

EditResourceCategoryDialogTest EditResourceCategoryDialogController "before each" hook: workFn 
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.9/$injector/modulerr?p0=resourceofferingsApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20 

示例代碼:

define(function (require) { 
    "use strict"; 

    var assert = require('chai').assert; 
    var sinon = require('sinon'); 
    var angular = require('angular'); 
    var angularMocks = require('angular.mocks'); 

    require('resourceofferings/app'); 
    require('dialog path'); 

    describe('EditResourceCategoryDialogTest', function() { 

     beforeEach(module('resourceofferingsApp')); 

     describe('EditResourceCategoryDialogController', function() { 
      var $scope, ctrl; 

      //you need to inject dependencies first 
      beforeEach(inject(function ($rootScope, $injector) { 
       $scope = $rootScope.$new(); 
      })); 

      it('initialization test (create mode)', inject(function ($controller) { 

       ctrl = $controller("EditResourceCategoryDialogController", { 
        $scope: $scope, 
        $uibModalInstance: null, 
        options: { 
         isEditMode: false 
        } 
       }); 

       assert.equal($scope.isEditMode, false); 
      })); 

     }); 
    }); 
}); 

其確切抵達該處失敗:

beforeEach(inject(function ($rootScope, $injector) { 
    $scope = $rootScope.$new(); 
})); 

請幫我解決這個問題..

在此先感謝。

回答

0

嘗試......

describe('controllers', function(){ 
    beforeEach(inject(function($rootScope, $controller) { 
     scope = $rootScope.$new(); // this is what you missed out 
     controller = $controller('EditResourceCategoryDialogController', { 
      $scope: scope, 
      $uibModalInstance: null, 
      options: { 
       isEditMode: false 
      } 
     }); 
    })); 
}); 

更新:根據角...

A common reason why the module fails to load is that you've forgotten to include the file with the defined module or that the file couldn't be loaded.

你確定所有需要的文件都加載?

+0

謝謝史密斯。但是我仍然得到同樣的錯誤:「每個鉤子之前:workFn」 –