gpt4 book ai didi

javascript - Angular Jasmine 测试找不到模块

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:15:54 25 4
gpt4 key购买 nike

所以我的测试提示找不到ui.bootstrap

INFO [karma]: Karma v0.10.2 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
WARN [watcher]: Pattern "/home/xenoterracide/lm/frontend/test/mock/**/*.js" does not match any file.
INFO [Chrome 30.0.1599 (Linux)]: Connected on socket 15lSt3HPpk9b-rKPvQzY
Chrome 30.0.1599 (Linux) Controller: Week should attach days of the week to scope FAILED
Error: No module: ui.bootstrap
at Error (<anonymous>)
at /home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:1211:17
at ensure (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:1152:38)
at module (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:1209:14)
at /home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:2904:24
at Array.forEach (native)
at forEach (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:130:11)
at loadModules (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:2900:5)
at /home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:2905:38
at Array.forEach (native)
TypeError: Cannot read property 'days_of_the_week' of undefined
at null.<anonymous> (/home/xenoterracide/lm/frontend/test/spec/controllers/week.js:20:17)
Chrome 30.0.1599 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.126 secs / 0.017 secs)
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

Elapsed time
concurrent:test 1s

这是我的 app.js,这是我加载 ui.bootstrap 的地方。

'use strict';

angular.module('lmApp', [
'ui.bootstrap',
'ui.router'
])
.config(['$stateProvider', '$urlRouterProvider',
function ( $stateProvider, $urlRouterProvider ) {
$urlRouterProvider.otherwise('/')
$stateProvider.state('index', {
url: "", // root
views: {
"Nav": { templateUrl: "views/nav.html" },
"Week": { templateUrl: "views/week.html" },
},
})
}
])
.factory('now', function () { return new Date })
;

这是我的测试

'use strict';

describe('Controller: Week', function () {

// load the controller's module
beforeEach(module('lmApp'));

var MainCtrl,
scope;

// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
MainCtrl = $controller('Week', {
$scope: scope
});
}));

it('should attach days of the week to scope', function () {
expect(scope.days_of_the_week.length).toBe(7);
});
});

最佳答案

问题在错误日志中指出:

Error: No module: ui.bootstrap

基于此,我猜测您在 Karma 配置文件(通常称为 karma.conf.js)中遗漏了一个步骤。您需要在配置中提供您的应用程序所需的所有必要库,以便 Karma 知道在运行测试之前将它们加载到内存中。当您调用 beforeEach(module('lmApp')); 时,Karma 会尝试创建您的 lmApp 模块,但无法创建,因为其声明的一个(或多个)依赖项不可用。

我有 99% 的把握,如果您只是将 ui.bootstrap 的源代码包含在您的 karma 配置的 files:{} 部分,它应该会启动工作。

请参阅业力文档 here了解更多信息。

关于javascript - Angular Jasmine 测试找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19412109/

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