gpt4 book ai didi

javascript - 需要/Angular/Karma/ui-router - 错误 : Could not resolve 'landing' from state ''

转载 作者:行者123 更新时间:2023-12-03 07:29:33 25 4
gpt4 key购买 nike

我已经在其他问题上看到过此症状,而我最接近我的问题是这个 Ionic 问题:

Could not resolve '...' from state ''

PhantomJS 1.9.8 (Mac OS X 0.0.0) Controller :ContainerCtrl 测试失败 错误:无法从状态“”解析“着陆”

我是 Angular 的 Karma 测试新手,并且很难调试范围问题。

app.js

.config(function($stateProvider, $urlRouterProvider) {
// For any unmatched url, redirect to landing
$urlRouterProvider.otherwise("/");

// Now set up the states
$stateProvider
.state('guide', {
url: "/guide",
templateUrl: "views/guide.html",
controller: 'SurveyController as main'
})
.state('stop', {
url: "/stop",
templateUrl: "views/stop.html",
controller: 'StopCtrl as stop'
})
.state('landing', {
url: "/",
templateUrl: "views/landing.html",
controller: 'AboutCtrl as about'
});
});

containerSpec.js

define(['angular', 'angular-mocks', 'app'], function(angular, mocks, app) {
'use strict';

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

var ContainerCtrl, $state;

beforeEach(angular.mock.module('app.controllers.ContainerCtrl', 'ui.router'));


beforeEach(angular.mock.inject(function($rootScope, $controller, _$state_) {
//create an empty scope
ContainerCtrl = $rootScope.$new();
$state = _$state_;
//declare the controller and inject our empty scope
$controller('ContainerCtrl', { $scope : ContainerCtrl });

}));

});
});

container.js

define([
'angular',
'services/dataservice'], function (
angular,
dataService // jshint ignore:line
) {
'use strict';

angular.module('oslerApp.controllers.ContainerCtrl', [])
.controller('ContainerCtrl', [
'$scope',
'$rootScope',
'$state',
function(
$scope,
$rootScope,
$state) {

$state.go('landing');

}]);

});

更新:更改为logLevel:config.LOG_DEBUG,我看到Spec文件的加载顺序领先于app.js和ui.router文件。

INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket B-PFcQHXMLMqx8cOoznu with id 19321969
DEBUG [launcher]: PhantomJS (id 19321969) captured in 4.068 secs
DEBUG [web-server]: serving: /deploy/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /deploy/node_modules/requirejs/require.js
DEBUG [web-server]: serving (cached): /deploy/node_modules/karma-requirejs/lib/adapter.js
DEBUG [web-server]: serving (cached): /deploy/test/test-main.js
DEBUG [web-server]: serving (cached): /deploy/bower_components/jquery/dist/jquery.js
DEBUG [web-server]: serving (cached): /deploy/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving (cached): /deploy/node_modules/karma-jasmine/lib/boot.js
DEBUG [web-server]: serving (cached): /deploy/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving (cached): /deploy/bower_components/angular/angular.js
DEBUG [web-server]: serving (cached): /deploy/test/spec/controllers/containerSpec.js
DEBUG [web-server]: serving (cached): /deploy/test/spec/services/dataserviceSpec.js
DEBUG [web-server]: serving (cached): /deploy/app/scripts/app.js
DEBUG [web-server]: serving (cached): /deploy/bower_components/angular-ui-router/release/angular-ui-router.js
DEBUG [web-server]: serving (cached): /deploy/app/scripts/services/dataservice.js
DEBUG [web-server]: serving (cached): /deploy/app/scripts/controllers/container.js

最佳答案

您正在尝试通过 $state.go 命令进入 landing 状态,但尚未定义状态 landing在你的 app.js 中。解决这个问题,看看你进展如何。

关于javascript - 需要/Angular/Karma/ui-router - 错误 : Could not resolve 'landing' from state '' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35855705/

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