gpt4 book ai didi

javascript - Karma Jasmine Angular 未定义

转载 作者:搜寻专家 更新时间:2023-11-01 00:32:08 24 4
gpt4 key购买 nike

我正在尝试学习如何使用 angular 和 karma 来测试 angularjs 和 nodejs。我使用了 Noesavy 的 youtube 视频来学习如何设置 karma 和 jasmine。他的示例运行良好,但是当我尝试将 jasmine 和 karma 与我自己的代码一起使用时,我得到了未定义的 Angular 。我的代码贴在下面:

密码脚本.js

angular.module('myApp', []).controller('S',
['$scope',
function($scope){

$scope.checkPass = function(insert_password, confirm_password){

if(insert_password == confirm_password){
$scope.passBoole = true;
} else {
$scope.passBoole = false;
}
};


}]);

检查通行证

describe("Password Controller", function(){
var $rootScope,
$scope,
controller;

beforeEach(function(){
module('myApp');

inject(function($injector){
$rootScope = $injector.get('$rootScope');
$scope = $rootScope.$new();
controller = $injector.get('$controller')("S", {$scope: $scope});
});
});

describe('Password check', function(){
it('should set $scope.passBoole top false', function(){
checkPass("bob", "tom");
expect($scope.passBoole).toEqual(false);
})
it('should set scope.passBoole to true', function(){
checkPass("bob", "bob");
expect($scope.passBoole).toEqual(true);
});
});

});

karma .conf.js

// Karma configuration
// Generated on Thu Dec 11 2014 17:07:06 GMT+0000 (GMT)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// 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/**/*.js',
'test/**/*.js'
],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};

我真的不知道为什么会这样,非常感谢任何帮助。

最佳答案

files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'app/**/*.js',
'spec/**/*.js'
],

我知道这是一个迟到的答案,但我遇到了同样的问题,删除 './' 为我解决了这个问题

关于javascript - Karma Jasmine Angular 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27429688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com