gpt4 book ai didi

angularjs - 使用 karma 和 jasmine 测试 angularjs 时出现此错误 "Error: beforeEach expects a function argument; received [object Object]"

转载 作者:行者123 更新时间:2023-12-05 07:41:29 26 4
gpt4 key购买 nike

enter image description here

我在使用 karma 和 jasmine 测试 angularjs 时收到此错误“错误:beforeEach 需要一个函数参数;收到 [object Object]”。我尝试了很多方法,但无法找到解决方案。我在下面给出了我的规范代码和 karma conf js。供您引用,由于某些依赖性,我确实在我的应用程序中使用了 requirejs

//Service Spec code :
define([], function () {
'use strict';
describe('search Service spec', function () {
var searchService;
beforeEach(angular.module('flightRouteApp', []));
describe('service methods', function () {
it('should calculate the length of the element', inject(function (searchService) {
expect(searchService).toBeDefined();
}));
});
});
});
// Karma configuration
// Generated on Sun Mar 05 2017 09:17:46 GMT+0100 (W. Europe Standard Time)
/* global module */
"use strict";
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: [
{pattern:'node_modules/angular/angular.js',watched: true, included: true, served: true},
{pattern:'node_modules/angular-mocks/angular-mocks.js',watched: true, included: true, served: true},
{pattern:'app/js/flightRoute.js',watched: true, included: true, served: true},
{pattern:'app/js/services/*.js',watched: true, included: true, served: true},
{pattern:'app/js/**/*.js',watched: true, included: true, served: true},
{pattern:'tests/test-main.js',watched: true, included: true, served: true},
{pattern: 'tests/**/*.Spec.js',watched: true, included: true, served: true}
],

// list of files to exclude
exclude: [ ],

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
/*reporters: ['progress','coverage'],*/
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
preprocessors: {
'app/js/**/*.js': 'coverage'
},

// web server port
port: 9876,
coverageReporter: {includeAllSources: true, reporters:[{type: 'html', dir:'coverage/'}]},

// enable / disable colors in the output (reporters and logs)
colors: true,
//vel 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: false,

// 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
})
}

最佳答案

只需更改您的 beforeEach 即可:

beforeEach(module('flightRouteApp'));

关于angularjs - 使用 karma 和 jasmine 测试 angularjs 时出现此错误 "Error: beforeEach expects a function argument; received [object Object]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45283595/

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