0

私は Karma でいくつかのテストを書き始めています。懇願するために、単純なテストを試すことにしました。ただし、2 つのエラーが発生します (1 つはジャスミンに関連し、もう 1 つは inject に関連しています (angular.inject を試すと同じエラーが発生します)。

two errors Firefox 22.0 (Windows) ConfigurationController encountered a declaration exception FAILED
    TypeError: this.func.apply is not a function in 
/adapter/lib/jasmine.js?1374202126000 (line 1145)
    testacular.js:106
    :9876/context.html:40

    ReferenceError: inject is not defined in     /var/lib/tomcat7/webapps/lunchtime/test/controllers/configuration-controller.js (line 7)
    @/var/lib/tomcat7/webapps/lunchtime/test/controllers/configuration-controller.js:7
    @/var/lib/tomcat7/webapps/lunchtime/test/controllers/configuration-controller.js:3

Firefox 22.0 (Windows): 1 の 1 を実行 (1 失敗) (0.48 秒 / 0.011 秒)

私は単純なコントローラーを持っています:

app.controller("ConfigurationController", ["$scope", "$http", function($scope, $http) {
$scope.configuration = {};
}]);

そして簡単なテスト:

'use strict';

describe('ConfigurationController', function() {
var scope, ctrl;
//you need to indicate your module in a test
beforeEach(angular.module('AmphinicyLunch'));
beforeEach(inject(function($rootScope) {
    scope = $rootScope.$new();
    ctrl = $controller("ConfigurationController", {$scope: scope})
}));

it("should have defined configuration", function($scope) {
    dump($scope.configuration);
    expect($scope.configuration).toEqual({});
});

});

4

2 に答える 2

2

挿入エラーの場合、angular-mocks.js を含める必要があります。module と inject の両方がそのファイルで定義されています。ジャスミンのエラーについてはわかりません。

于 2013-07-29T19:58:25.587 に答える