leo*_*ini 4 testing jasmine angularjs karma-runner
我正在与Karma和Jasmine进行Angular测试。完成karma init并编写了家用控制器的第一个测试后,我不断得到Executed 0 of 0 ERROR。似乎文件中没有该文件。
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'public/assets/libs/angular/angular.min.js',
'bower_components/angular-mocks/angular-mocks.js',
'public/app/app.module.js',
'public/app/app.config.js',
'public/app/**/*.js',
'test/unit/**/*.spec.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 3030,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
}); //config.set
} //module.export
Run Code Online (Sandbox Code Playgroud)
测试(固定)
describe('HomeController', function() {
//Inject 'app' module into this spec.
beforeEach(module('app'));
//Inject instance of Scope.
var homeController;
beforeEach(inject(function($rootScope, $controller) {
//create a new scope
scope = $rootScope.$new();
//create new controller, using the newly created scope
HomeController = $controller('HomeController', {
$scope: scope
});
}));
//Set expectations
it('the message should say Hello World', function(HomeController) {
expect(scope.message).toBe('Hello World');
});
});
Run Code Online (Sandbox Code Playgroud)
和HomeController:
(function() {
'use strict';
angular
.module('app')
.controller('HomeController', HomeController);
HomeController.$inject = ['$scope', '$log'];
function HomeController($scope, $log) {
/*jshint validthis: true*/
var vm = this;
vm.message = 'Hello World';
} //HomeController()
})(); //Controller
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
小智 5
对于所有也遇到“Executed 0 of 0 ERROR”问题的人:
以下是如何更好地调试此错误,因为命令行中的日志消息可能会被截断或没有足够的帮助:
在 karma 的 Browser 实例(例如 Chrome)中,karma.js在以下函数中设置一个断点:
this.error = function (msg, url, line) {
由于msg将被传输到命令行日志的字符串表示不是很有帮助,在这里分析一下。
| 归档时间: |
|
| 查看次数: |
6566 次 |
| 最近记录: |