I am writing the simplest component that is using a routeLink:
@Component({
selector: 'memorySnippet',
templateUrl: '<div class="memory-snippet-wrapper" *ngIf="memory"
[routerLink]="['MainPanel', 'MemoryPanel', {'id' : this.memory.id}]">',
directives: [CORE_DIRECTIVES, ROUTER_DIRECTIVES]
})
export class MemorySnippetComponent {
@Input() memory: Memory;
}
The problem occurs when I try testing this component. The moment I add the router link Karma is complaining about missing providers:
After adding all the providers Karma is asking I get this:
beforeEachProviders(() => [
MemorySnippetComponent,
MEMORY_SERVICE_PROVIDERS,
ROUTER_PROVIDERS,
ApplicationRef
]);
But when I run the test I get this error:
EXCEPTION: EXCEPTION: Error during instantiation of Token RouterPrimaryComponent! (RouterLink -> Router -> RouteRegistry -> Token RouterPrimaryComponent).
ORIGINAL EXCEPTION: unimplemented
ORIGINAL STACKTRACE: Error: unimplemented
What am I doing wrong??? Is Angular 2 (2.0.0-beta.1) just not ready for testing components with router directives?
For RC4 with new router now use ...
A github project using this approach is ...
https://github.com/danday74/angular2-coverage
You should have a
beforeEachProviders
method looking like:MockApplicationRef
is provided by the framework for this kind of tests.