Hello,
I am writing Karma test for a simple page that has tabstrip with each tab
routing to different component.
I have written a test for it. The first "it" statement passes OK, but when
I add second "it" I have the following error:
Chrome 44.0.2403 (Windows 7 0.0.0) collections component Should be
switchable to Search FAILED
Failed: EXCEPTION: Error during instantiation of Router!
(CollectionsApp -> Router).
ORIGINAL EXCEPTION: Route config should contain exactly one "as" or
"name" property.
ORIGINAL STACKTRACE:
Error: Route config should contain exactly one "as" or "name"
property.
at new BaseException
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:8080:21)
at Object.normalizeRouteConfig
(D:/angularPOC/collections.ng/test/angular2/router.dev.js:1638:13)
at RouteRegistry.config
(D:/angularPOC/collections.ng/test/angular2/router.dev.js:2197:41)
at
D:/angularPOC/collections.ng/test/angular2/router.dev.js:2232:28
at Array.forEach (native)
at Array.forEach
(D:/angularPOC/collections.ng/test/lib/es6-shim.js:1107:14)
at RouteRegistry.configFromComponent
(D:/angularPOC/collections.ng/test/angular2/router.dev.js:2231:23)
at new RootRouter
(D:/angularPOC/collections.ng/test/angular2/router.dev.js:2820:21)
at
D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:1384:20
at Injector._instantiate
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11926:19)
at Injector._instantiateProvider
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11859:21)
at Injector._new
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11849:19)
at InjectorDynamicStrategy.getObjByKeyId
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11733:42)
at Injector._getByKeyDefault
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:12048:33)
at Injector._getByKey
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:12002:21)
at Injector._getByDependency
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11990:21)
at Injector._instantiate
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11887:32)
at Injector._instantiateProvider
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11859:21)
at Injector._new
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11849:19)
at InjectorInlineStrategy.instantiateProvider
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11609:28)
at ElementInjectorInlineStrategy.hydrate
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:13234:20)
at ElementInjector.hydrate
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:12882:22)
at AppViewManagerUtils._hydrateView
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:9662:31)
at AppViewManagerUtils.hydrateRootHostView
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:9596:12)
at AppViewManager_.createRootHostView
(D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:11268:19)
at
D:/angularPOC/collections.ng/test/angular2/angular2.dev.js:14531:46
at Zone.run
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:138:17)
at Zone.run
(D:/angularPOC/collections.ng/node_modules/angular2/bundles/testing.dev.js:2544:30)
at zoneBoundFn
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:111:19)
at lib$es6$promise$$internal$$tryCatch
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:1511:16)
at lib$es6$promise$$internal$$invokeCallback
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:1523:17)
at lib$es6$promise$$internal$$publish
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:1494:11)
at
D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:243:5
at microtask
(D:/angularPOC/collections.ng/node_modules/angular2/bundles/testing.dev.js:2557:15)
at Zone.run
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:138:17)
at Zone.run
(D:/angularPOC/collections.ng/node_modules/angular2/bundles/testing.dev.js:2544:30)
at zoneBoundFn
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:111:19)
at MutationObserver.lib$es6$promise$asap$$flush
(D:/angularPOC/collections.ng/test/angular2/angular2-polyfills.js:1305:9)
I suppose something is wrong with my router configuration in the test
environment, but I have no clue how I could fix it.
I have attached my unit test.
Regards,
Vasil
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
import {
iit,
it,
ddescribe,
describe,
expect,
inject,
injectAsync,
TestComponentBuilder,
beforeEachProviders,
beforeEach,
fakeAsync,
tick
} from 'angular2/testing';
import { provide } from 'angular2/core';
import { Router, Location, RouteRegistry, ROUTER_PRIMARY_COMPONENT } from 'angular2/router';
import {CollectionsApp} from '../collections/collectionsApp';
import {Dashboard} from '../collections/dashboard/dashboard';
import {RootRouter} from 'angular2/src/router/router';
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
describe('collections component', () => {
var location: Location;
beforeEachProviders(() => [
RouteRegistry,
DirectiveResolver,
Location,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: CollectionsApp}),
provide(Router, {useClass: RootRouter})
]);
beforeEach(inject([Location], (loc: Location) => {
location = loc;
}));
it('Should be initialized with Dashboard', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(CollectionsApp).then((fixture) => {
fixture.detectChanges();
var component : CollectionsApp = fixture.debugElement.componentInstance;
var element: HTMLElement = fixture.debugElement.nativeElement;
// Ensures the 'select' property of CollectionsApp has correct value
expect(component.select).toBe('Dashboard');
// Ensures router is positioned correctly
expect(location.path()).toBe('');
// Ensures correct tab is selected
var selectedTab: Element = element.querySelector('li.k-state-active span.k-link');
expect(selectedTab).toHaveText('Dashboard');
var imgSrcAttribute: String = selectedTab.querySelector('img').getAttribute('src');
expect(imgSrcAttribute).toContain('dashboard');
// Ensures correct child component is selected
expect(fixture.debugElement.componentViewChildren.length).toBe(1);
var dashboardComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
expect(dashboardComponent.model).toBe('Dashboard');
});
}));
it('Should be switchable to Search', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(CollectionsApp).then((fixture) => {
fixture.detectChanges();
});
}));
});