业力茉莉花角度未定义

Karma Jasmine Angular not defined

本文关键字:未定义 茉莉花      更新时间:2023-09-26

我正在尝试学习如何使用angularjs和karma来测试angularjs和nodejs。我使用Noesavy的YouTube视频来学习如何设置业力和茉莉花。他的例子工作得很好,但是当我尝试在我自己的代码中使用茉莉花和业力时,我得到了未定义的角度。我的代码发布在下面:

密码脚本.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);
    });
 });
});

业力.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'
],

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

请将 karma.config 中的 file:[] block 的内容替换为以下内容.js

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