【发布时间】:2016-01-07 15:36:52
【问题描述】:
我正在尝试使用 ncy-angular-breadcrumb,它使用 ui 路由。我设置了一个模块来容纳 ui 路由:
(function () {
var app = angular.module('configurator.uiroutes', ['ui.router', 'ncy-angular-breadcrumb']);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('home', {
url: '/',
ncyBreadcrumb: {
label: 'Series'
}
});
}]);
})();
我有这个测试,看看路线是否有效:
describe('Configurator UI Routes', function () {
beforeEach(module('configurator.uiroutes'));
beforeEach(module('ui.router'));
var $state, $rootscope, state = '/';
// Inject and assign the $state and $rootscope services.
beforeEach(inject(function (_$state_, _$rootScope_) {
$state = _$state_;
$rootscope = _$rootScope_;
}));
//Test whether the url is correct
it('should activate the state', function () {
$state.go(state);
$rootscope.$digest();
expect($state.current.name).toBe('home');
});
});
产生此错误的原因:
Error: Could not resolve '/' from state ''
我只是没有得到 UI 路由器以及它是如何工作的,或者它应该做什么。我只想获取部分 url 并将该信息传递给 ncyBreadcrumb,但我什至无法让基本 URL 工作。
任何指示或帮助都会很棒!
编辑:我已经通过在测试中将“/”替换为“home”来通过测试。我更大的问题是:有没有办法测试当 URL '/' 被击中时, state.current.name 变成了 'home'。在我使用该应用程序时,这似乎没有发生,我希望单元测试可以帮助告诉我原因。
这是一个单页应用程序,如果相关的话。
【问题讨论】:
标签: javascript angularjs unit-testing jasmine angular-ui-router