1
我複製了從here進行單元測試的angularjs示例。由於它只是直接實現這個例子,所以我對所引發的錯誤感到困惑。Angularjs Jasmine單元測試
我在Linux中工作並使用括號作爲IDE。
請讓知道什麼是缺少的元素來運行茉莉花測試。
茉莉花的輸出繼電器
PasswordController encountered a declaration exception.
ReferenceError: module is not defined
controller.js
angular.module('app', [])
.controller('PasswordController', function PasswordController($scope) {
$scope.password = '';
$scope.grade = function() {
var size = $scope.password.length;
if (size > 8) {
$scope.strength = 'strong';
} else if (size > 3) {
$scope.strength = 'medium';
} else {
$scope.strength = 'weak';
}
};
});
控制器spec.js
describe('PasswordController', function() {
beforeEach(module('app'));
var $controller;
beforeEach(inject(function(_$controller_){
// The injector unwraps the underscores (_) from around the parameter names when matching
$controller = _$controller_;
}));
describe('$scope.grade', function() {
it('sets the strength to "strong" if the password length is >8 chars', function() {
var $scope = {};
var controller = $controller('PasswordController', { $scope: $scope });
$scope.password = 'longerthaneightchars';
$scope.grade();
expect($scope.strength).toEqual('strong');
});
});
});
卡瑪conf.js
// list of files/patterns to load in the browser
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'app/controllers/*.js',
'test/controllers/*.js'
],
噶輸出
/var/www/html/angular-jasmine-testing $ kma start karma.conf.js
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 41.0.2272 (Linux)]: Connected on socket vZCR4hAC8uU7LutFNVl3 with id 44440115
Chrome 41.0.2272 (Linux): Executed 1 of 1 SUCCESS (0.042 secs/0.035 secs)
你確定你在你的項目中的所有這些文件?你可以發佈完整的業力輸出嗎? –
Karma似乎成功地運行了測試:「執行了1個1成功」。 Brackets是否有可能試圖在Karma之外運行Jasmine規格? –
我不認爲這個問題是與括號,因爲我跑了一個簡單的JavaScript測試,它得到執行。 –