I'm implementing ncy-angular-breadcrumb with UI routes. I have a module dedicated to hosting the UI routes:
(function () {
var app = angular.module('configurator.uiroutes', ['ui.router', 'ncy-angular-breadcrumb']);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('home', {
url: '/',
ncyBreadcrumb: {
label: 'Series'
}
});
}]);
})();
To test if the route is functioning correctly, I've written this code:
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');
});
});
However, I encountered an error:
Error: Could not resolve '/' from state ''
I am struggling to understand how UI Router works and what its intended functionality is. I simply want to extract parts of the URL and pass that information to ncyBreadcrumb. Unfortunately, even establishing the base URL is proving challenging.
If anyone has any tips or guidance to offer, it would be greatly appreciated!
Edit: By substituting '/' with 'home' in the test, I managed to make it pass. My main concern now is: is there a way to verify that when the URL '/' is accessed, the state.current.name becomes 'home'? In actual usage of the application, this transition doesn't seem to occur, and I'm hoping the unit test can shed light on why.
Just to mention, this is a single-page application.