mardi 2 août 2016

angular2 cli test missing params for Router

I have application in agular2 created with CLI component looks like this:

import { Component, OnInit, Input, Output, EventEmitter, Renderer, AfterViewInit } from '@angular/core';

@Component({
  selector    : 'app-modal-dialog',
  templateUrl : 'app/shared/modal-dialog/modal-dialog.component.html'
})
export class ModalDialogComponent implements OnInit, AfterViewInit {

  @Input() title            : string;
  public modalDialogVisible : boolean = false;
  public modalQuestion      : string;
  public modalData          : any;
  @Output() confirmAction   : EventEmitter<any>   = new EventEmitter<any>( );

  protected documentEscapeListener : any;

  constructor( protected _renderer: Renderer ) {

  }
  ... etc

CLI created spec for test that need to be modified to accommodate dependency injection:

import { By }           from '@angular/platform-browser';
import { DebugElement, Renderer } from '@angular/core';

import {
  beforeEach, beforeEachProviders,
  describe, xdescribe,
  expect, it, xit,
  async, inject,
} from '@angular/core/testing';

import { ModalDialogComponent } from './modal-dialog.component';


beforeEachProviders( ( ) => [ ModalDialogComponent, Renderer ] );

describe('Component: ModalDialog', ( ) => {

  it('should create an instance', 
    inject( [ Renderer ], 
          ( _renderer : Renderer 
          ) => {

    let component = new ModalDialogComponent( _renderer );
    expect(component).toBeTruthy();
  } ) );
});

when running ng test I am facing errors on test cases about Router.

Error: Cannot resolve all parameters for 'Router'(?, ?, ?, ?, ?, ?, ?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Router' is decorated with Injectable.

This component has nothing to do with Router and still throwing Router related error - other components have Router as DI and are injected to test case same way like Renderer in example.

What I am doing wrong ?

Aucun commentaire:

Enregistrer un commentaire