当我尝试运行我的茉莉花测试时,正在测试我的角度客户指令"书籍指令"使用test-runner karma我得到以下输出错误:(我从每个脚本文件中获取各种TypeErrors,甚至没有找到我的测试,更不用说显示测试失败了))
业力输出
------ Discover test started ------
Error: TypeError: undefined is not an object (evaluating 'angular.module')
in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/scripts/angular-route.js (line 24)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-route.js
Error: TypeError: undefined is not an object (evaluating 'angular.$$minErr')
in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/scripts/angular-sanitize.js (line 8)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-sanitize.js
Error: ReferenceError: Can't find variable: define
at global code in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/tests/newfeaturetests/directivetest.js (line 3)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\tests\newfeaturetests\directivetest.js
Error: TypeError: Attempted to assign to readonly property.
in file:///c:/users/ray/documents/visual%20studio%202013/projects/requirejsdemo/requirejsdemo/scripts/angular-mocks.js (line 17)
While Running:c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-mocks.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-mocks.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-route.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-sanitize.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular-scenario.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\angular.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\scripts\jasmine.js
[Karma] [Warning] [Discover] Could not get settings for c:\users\ray\documents\visual studio 2013\projects\requirejsdemo\requirejsdemo\tests\newfeaturetests\directivetest.js
========== Discover test finished: 0 found (0:00:17.4009953) ==========
karma.conf文件
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', 'requirejs'],
// list of files / patterns to load in the browser
files: [
"Scripts/angular.js",
{ pattern: "Scripts/require.js", included: false },
{ pattern: "Scripts/jasmine.js", included: false },
{ pattern: "Scripts/angularAMD.js", included: false },
{ pattern: "Scripts/jquery-1.8.2.js", included: false },
{ pattern: "Js/**/*.js", included: false },
{ pattern: "tests/NewFeatureTests/*.js", included: false },
{ pattern: "Js/NewFeature/*.html", include: false },
"tests/test-main.js"
],
// list of files to exclude
exclude: [
"Js/main.js"
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"Js/**.*.html": ["ng-html2js"]
},
// 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,
plugins: [
'karma-ng-html2js-preprocessor'
],
// 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
})
}
茉莉花测试
'use strict'
define(['angular', 'jquery',], function (angular) {
describe('bookDirective', function () {
var el;
// Load the myApp module, which contains the directive
beforeEach(module('testModule'));
beforeEach(module('Js/NewFeature/Book.html'));
// Store references to $rootScope and $compile
// so they are available to all tests in this describe block
beforeEach(inject(function ($compile, $rootScope) {
// The injector unwraps the underscores (_) from around the parameter names when matching
scope = _$rootScope_;
scope.color = "red";
scope.title = "ghost";
//create and compile directive
el = angular.element("<book title='Ghost' color='red'></book>");
// compile the dom node and apply the scope, this will return a getter function
$compile(el)(scope);
scope.$digest(); // update the html
}));
it('background colour of book should be red', function () {
// check if background color is red
expect(el.css('background-color').toEqual('red'));
});
});
});
如何让我的测试运行?
答案 0 :(得分:0)
你的基本路径是 basePath:'.. /',。所以,文件数组应该是
files: [
"../scripts/angular.js",
"../scripts/angular-route.js",
"../scripts/angular-mocks.js",
"../scripts/angular-sanitize.js",
"../scripts/angular-scenario.js",
"../scripts/jasmine.js",
"../tests/newfeaturetests/directivetest.js",
"../tests/test-main.js"
]
请检查基本路径。
请检查 index.html 文件,查看您所包含的所有脚本JS,并将其列在文件数组中。否则,如果其中一个脚本将导致错误,则会导致错误对他人的依赖。
同样在你的茉莉花测试中 beforeEach(模块('Js / NewFeature / Book.html'));
这是错误的。这不是使用angular app注册的模块名称。请检查它。删除它。
另请参阅directive testing了解更多信息。