gpt4 book ai didi

angularjs - karma Jasmine : Executed 0 of 0 Error

转载 作者:行者123 更新时间:2023-11-28 19:50:53 25 4
gpt4 key购买 nike

我正在使用 Karma 和 Jasmine 进行 Angular 测试。在完成 karma init 并为家庭 Controller 编写第一个测试后,我一直收到 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

测试(固定)

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');
});


});

和 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

感谢您的帮助。

最佳答案

我想通了。测试 it('...') 位于 beforeEach() block 内,因此有 0 个测试。它现在在它自己单独的 block 中,如下所示。

关于angularjs - karma Jasmine : Executed 0 of 0 Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31707902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com