Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?) in Angular RC 5 when unit testing Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?) in Angular RC 5 when unit testing javascript javascript

Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?) in Angular RC 5 when unit testing


Was finally able to fix it, and it was as simple as this:

beforeEach(() => addProviders([    {         provide: Router,         useClass: class { navigate = jasmine.createSpy("navigate"); }    }]));


for me it worked to add the RouterTestingModule

  import { RouterTestingModule } from '@angular/router/testing';  beforeEach(async(() => {    TestBed.configureTestingModule({      imports: [        RouterTestingModule      ],      declarations: [ HomeComponent ]    })    .compileComponents();  }));


In my case, I had Router in providers and RouterTestingModule in imports. Guess this was causing a conflict. The following configuration worked:

    TestBed.configureTestingModule({        declarations: [Component],        imports: [            RouterTestingModule,                     ],        providers: [         ...         //Remove Router from providers        ]                  });