sto scrivendo la componente più semplice che utilizza un routeLink:angolari 2: componenti di test con router
@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;
}
Il problema si verifica quando provo testare questa componente. Nel momento in cui aggiungo il link router Karma si lamenta provider mancanti:
Dopo aver aggiunto tutti i fornitori di Karma sta chiedendo ottengo questo:
beforeEachProviders(() => [
MemorySnippetComponent,
MEMORY_SERVICE_PROVIDERS,
ROUTER_PROVIDERS,
ApplicationRef
]);
Ma quando ho eseguito il test ottengo questo errore:
EXCEPTION: EXCEPTION: Error during instantiation of Token RouterPrimaryComponent! (RouterLink -> Router -> RouteRegistry -> Token RouterPrimaryComponent).
ORIGINAL EXCEPTION: unimplemented
ORIGINAL STACKTRACE: Error: unimplemented
Cosa sto facendo male ??? Angular 2 (2.0.0-beta.1) non è ancora pronto per testare componenti con direttive router?
Questa sarebbe la mia interpretazione di questo errore. È ancora in versione beta e le guide di testing non sono state rilasciate per questo tipo di test. Forse potresti trovare il RouterPrimaryComponent nel sorgente e implementare l'interfaccia, quindi usare 'provide (RouterPrimaryComponent, {useClass: MyRouterPrimaryComponent})' per sovrascriverlo e magari far funzionare i test. – SnareChops
controlla il repository con il seme di prova dal team di Angular -> https://github.com/juliemr/ng2-test-seed relativo da questo talk https://www.youtube.com/watch?v=C0F2E-PRm44 –
Questa sintassi non ha bisogno di un ritorno? 'beforeEachProviders (() => {return [ MemorySnippetComponent, MEMORY_SERVICE_PROVIDERS, ROUTER_PROVIDERS, ApplicationRef ]}); –