2016-06-07 7 views
3

ich meine Tests leite mit Karma und Phantom, auch bin ich mit Mokka und Sinon und Tests werden immer mit folgenden Fehler fehlgeschlagen:„vor jedem“ Haken: workFn Fehler

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 

Beispielcode:

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); 
      })); 

     }); 
    }); 
}); 

Seine genau hier versagt bekommen:

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

mir bitte helfen, dieses Problem zu beheben ..

Vielen Dank im Voraus. diese

Antwort

0

Versuchen ...

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 
      } 
     }); 
    })); 
}); 

Update: Laut Angular ...

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.

Bist du sicher, dass alle benötigten Dateien geladen?

+0

Dank Smith. Aber immer noch bekomme ich denselben Fehler: "vor jedem" hook: workFn –