Angularjs 未能实例化模块,KARMA
我已经用AngularJS实现了我的web站点,现在,我必须进行单元测试,以验证我的函数的正确功能 我在网上找了很多教程,但显然,我的应用程序结构不允许使用karma和jasmin进行测试 让我解释一下,我有一个网站,只有一个单页HTML,它与一个控制器(一个文件.js)链接,我从未使用NPM安装Angular,但我使用以下工具导入它:Angularjs 未能实例化模块,KARMA,angularjs,unit-testing,jasmine,karma-jasmine,karma-runner,Angularjs,Unit Testing,Jasmine,Karma Jasmine,Karma Runner,我已经用AngularJS实现了我的web站点,现在,我必须进行单元测试,以验证我的函数的正确功能 我在网上找了很多教程,但显然,我的应用程序结构不允许使用karma和jasmin进行测试 让我解释一下,我有一个网站,只有一个单页HTML,它与一个控制器(一个文件.js)链接,我从未使用NPM安装Angular,但我使用以下工具导入它: <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
但当我使用:
因果报应
它没有检测到我的控制器
以下是我的控制台输出:
这是我的karma.conf.js:
// Karma configuration
// Generated on Thu Jun 14 2018 16:51:15 GMT+0200 (Paris, Madrid (heure d’été))
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: [ 'Scripts/angular.js','Scripts/angular-mocks.js','main.js','Tests/*.js'
],
// list of files / patterns 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,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
以及我如何声明我的控制器:
var app = angular.module('App', ['ngMaterial', 'ngMessages'])
app.controller('Ctrl', ['$rootScope', '$scope','$http','$timeout','$mdDialog','Global', 'projects', 'screens', 'users', 'licenses', function($rootScope, $scope, $http, $timeout, $mdDialog,Global, projects, screens, users, licenses) {
...
}
这是我的树文件夹:
-Root
|---node_modules
|---Tests
| |---test.js
|---Scripts
|---index.html
|---main.js <--- controller of my index.html
|---style.css
|---someFactory.js
-Root
|---节点单元
|---测验
||--test.js
|---剧本
|---index.html
|---main.js您可能需要在karma.conf.js中的枚举中使用main.js:文件:['Tests/*.js','*.html','main.js'],
好的,我刚刚添加了文件:['Tests/*.js','*.html','*.js']
看起来它不再在\base文件夹中搜索了。但我在加载控制器时总是会出现这样的错误:模块未定义
var app = angular.module('App', ['ngMaterial', 'ngMessages'])
app.controller('Ctrl', ['$rootScope', '$scope','$http','$timeout','$mdDialog','Global', 'projects', 'screens', 'users', 'licenses', function($rootScope, $scope, $http, $timeout, $mdDialog,Global, projects, screens, users, licenses) {
...
}
-Root
|---node_modules
|---Tests
| |---test.js
|---Scripts
|---index.html
|---main.js <--- controller of my index.html
|---style.css
|---someFactory.js