Javascript 业力没有定义
我试图学习如何使用angularjs和karma来测试angularjs和nodejs。我用Noesavy的youtube视频学习如何建立karma和jasmine。他的例子很好用,但当我试图用jasmine和karma来编写我自己的代码时,我得到了一个不确定的角度。我的代码发布在下面: passwordScript.jsJavascript 业力没有定义,javascript,angularjs,node.js,unit-testing,karma-runner,Javascript,Angularjs,Node.js,Unit Testing,Karma Runner,我试图学习如何使用angularjs和karma来测试angularjs和nodejs。我用Noesavy的youtube视频学习如何建立karma和jasmine。他的例子很好用,但当我试图用jasmine和karma来编写我自己的代码时,我得到了一个不确定的角度。我的代码发布在下面: passwordScript.js angular.module('myApp', []).controller('S', ['$scope', function($scope){ $scope.checkP
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
});
};
我真的不知道为什么会发生这种情况,非常感谢您的帮助。请用以下内容替换文件内容:[]karma.config.js中的block
files: [
'/bower_components/angular/angular.js',
'/bower_components/angular-mocks/angular-mocks.js',
'/bower_components/angular-resource/angular-resource.js',
'app/**/*.js',
'test/**/*.js'
],
我知道这是一个迟来的答案,但我遇到了同样的问题,删除了“/”为我解决了这个问题愚蠢的想法,但是你确定karma.conf.js中指定的angular.js路径是正确的吗?如果您在运行Karma的浏览器中进行检查,是否可以在开发控制台的源面板中找到它?是否可以尝试删除点“/bower_components/angular/angular.js”?您还应该将logLevel更改为logLevel:config.LOG_DEBUG,以获得更详细的输出,并找出问题的根源
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'app/**/*.js',
'spec/**/*.js'
],