- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有这样一个配置:
angular.module('myModule', ['ui.router'])
.config(['$stateProvider', function($stateProvider) {
$stateProvider
.state('app.home', {
abstract: true,
url: '/home',
template: '<div>Foo Bar</div>'
});
}]);
和像这样使用 jasmine 的单元测试:
'use strict';
describe('Module: myModule', function() {
var $rootScope, $state;
beforeEach(module('ui.router'));
beforeEach(module('myModule'));
beforeEach(inject(function(_$rootScope_, _$state_) {
$state = _$state_;
$rootScope = _$rootScope_;
}));
it('must have a route state for home', function(){
console.log($state.get('app.home')); // this returns null
});
});
但是我无法让配置中的状态显示在 $state.get()
返回的数组上
我还检查过,包含配置的文件已加载并且就在那里。谁能说我做错了什么?基本上我只是想测试我期望的状态是否存在于“myModule”的配置中
最佳答案
首先,你不需要这个
beforeEach(module('ui.router'));
因为您的模块已经将其列为依赖项。
我的猜测是,您没有引入父 app
状态,因此不会创建您的 app.home
状态。
假设您的 app
状态是在 myAppModule
中定义的,只需将您的 module
行更改为
beforeEach(module('myAppModule', 'myModule'));
如果您不想包含具有 app
状态的模块,请在您的模块之前包含一个配置函数,以创建一个假父状态。为此,您将需要包含ui.router
。
beforeEach(module('ui.router', function($stateProvider) {
$stateProvider.state('app', { abstract: true });
}, 'myModule'));
或者,您可以监视 $stateProvider.state
并使用 expect
来确保它是通过 app.home
调用的,例如
var $stateProvider;
beforeEach(module('ui.router', function(_$stateProvider_) {
$stateProvider = _$stateProvider_;
spyOn($stateProvider, 'state');
}, 'myModule'));
it('must have a route state for home', function() {
expect($stateProvider.state).toHaveBeenCalledWith('app.home', jasmine.any(Object));
});
关于javascript - 如果在 angularJS 的配置中配置,则测试 stateProvider 状态在 $state 上返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30316334/
我正在尝试将 $stateProvider 用于我的 url 路由。我想如果我使用$stateProvider,那么我就不需要使用$routeProvider了。这个对吗?我能够让我的 url 路由与
好吧,这个问题有点长,但我觉得我已经尝试了一切,所以如果可以的话,我希望你能帮助我:) 所以基本上我的系统有两种用户类型:Admin 和 Client 这些类型绑定(bind)到模板 tpl/app.
我是 Angular JS 的初学者,最近尝试了 $stateProvider,引用了一个教程-eggHead。从下面找到代码: 我没有得到正确的回应。 index.html
我真的搞不懂为什么这个标记不能识别我的 $stateProvider? Uncaught Error: [$injector:modulerr] Failed to instantiate modul
我一直在寻找这个难题的好答案,无论是routeProvider还是不行。 似乎$ routeProvider即将终止,并替换为$ stateProvider,不幸的是,我不知道此语句的准确性,而且st
我只是 angularjs 的初学者。我在下面的测试项目中没有看到任何错误和结果。索引.html User Auth
使用 angular-ui-router,如何使用 otherwise method上$stateProvider或者我该如何使用它? 最佳答案 您不能仅使用$stateProvider。 您需要注入
考虑这段代码: bank.config(function($stateProvider) { $stateProvider .state('main.bank', { url:
在我的主 index.html 文件中,我有以下简单标记... 在我的 app.js 中,我使用 $stateProvider 创建路由,以便我可以显示某些页面... app.confi
我刚开始更改其他人的一些代码,并尝试添加一个带有 Controller 的简单 html。我的问题是,我的 html 不会加载,如果我导航到它.. 系统只会显示:正在加载... 这是 html: t
我刚刚开始迁移到 AngularJS,并且 angular-ui/ui-router 中的 $stateProvider 已经出现问题框架。这是我到目前为止所拥有的: angular .mod
我有一个看起来像这样的 View : Data Package Management
我只是有 Angular 路线的问题。我有一个具有 4 个不同 View 的单页应用程序。我正在使用 $stateProvider 的 ui.router。主视图在路线上:https://testsi
我的页面上有如下按钮: 单击后我想使用 ui-sref 更改状态。我目前处于/status 状态,并且我想进入/status/{maId} 状态。 这是我的routes.js (functi
.controller('myCtrl', function($scope,$localstorage,$stateProvider, $urlRouterProvider) { $scope.g
我在我的应用程序中使用 angularJs 版本 1.4.5 和 angular-ui-router 版本 0.2.18。我注意到我的解析函数针对某个状态执行了两次。 我也尝试过使用更新的 angul
我目前正在阅读一个基于 AngularJS 1.4.8 的应用程序,该应用程序使用 AngularUI Router 0.2.15。 我注意到此应用程序有时使用依赖项 $state,有时使用依赖项 $
我得到了一个使用标准 $routeProvider 进行路由的当前 angularjs 应用程序。我打算将应用程序的一部分 $stateProvider 用作向导。 我这样声明父状态“Modal”和子
WikiApp.config(function config($stateProvider, $urlRouterProvider) { $stateProvider .state('
所以我在这个 Angular SPA 上工作了一段时间,遇到了一个有趣的现象,我希望有人能帮我弄清楚。 Safari 会给我 Did not parse stylesheet at 'http://l
我是一名优秀的程序员,十分优秀!