Abh*_*hee 3 unit-testing angularjs karma-jasmine
我是使用Karma-jasmine进行测试的新手,但是却出错了.
我的karma.conf.js
files: [
'test/*Spec.js',
'app/js/*.js'
],
Run Code Online (Sandbox Code Playgroud)
此错误在命令行中显示
Run Code Online (Sandbox Code Playgroud)Chrome 39.0.2171 (Windows 7) ERROR Uncaught TypeError: Cannot read property 'module' of undefined at D:/Test_Samples/WebContent/MyTest/app/js/angular-route.js:24 Firefox 34.0.0 (Windows 7) ERROR TypeError: angular is undefined at D:/Test_Samples/WebContent/MyTest/app/js/angular-route.js:24 IE 8.0.0 (Windows 7) ERROR 'undefined' is null or not an object at D:/Test_Samples/WebContent/MyTest/app/js/angular-route.js:24
角route.js:24
/* global -ngRouteModule */
var ngRouteModule = angular.module('ngRoute', ['ng']).provider('$route', $RouteProvider),
$routeMinErr = angular.$$minErr('ngRoute');
Run Code Online (Sandbox Code Playgroud)
您必须在测试之前导入角度和角度.这是我正在使用的配置示例:
files: [
{pattern: 'src/main/webapp/static/libs/jquery/dist/jquery.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular/angular.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular-resource/angular-resource.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular-mocks/angular-mocks.js', watch: false},
{pattern: 'src/main/webapp/static/libs/angular-ngkit/js/ngkit.js', watch: false},
'src/main/webapp/static/templates/angular/*.html',
'src/main/webapp/static/js/angular/**/*.js',
'src/test/js/spec/angular/*.js'
],
Run Code Online (Sandbox Code Playgroud)
这是避免观看库(watch: false)的最佳做法,因为这些文件在开发过程中不会改变!
定义" basePath"属性也很重要,因为所有路径都将使用该根解析!