ngtest - Routes Angular InjectorError

1

I'm using the angular route system and everything is ok:

export const routes: Routes = [    
  { path: '', redirectTo: '/login', pathMatch: 'full' },
  ... AutenticacaoRoutes,
  ... UsuarioRoutes,  
  { path: '**', component: Erro404Component },
];

@NgModule({
  imports: [ RouterModule.forRoot(routes) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule { }

I ran ng test and did not report any errors. After I added the lines below:

constructor(private router: Router) { }
this.router.navigate(['home']);

The application runs quietly but karma is experiencing the following error:

  

Error: StaticInjectorError (DynamicTestModule) [LoginComponent - > Router]:     StaticInjectorError (Platform: core) [LoginComponent - > Router]:       NullInjectorError: No provider for Router!

I tried to put RouterTestingModule into spec.ts and it still did not work.

    
asked by anonymous 13.07.2018 / 21:38

0 answers