Answers for "NullInjectorError: No provider for ActivatedRoute"

0

NullInjectorError: No provider for ActivatedRoute

//Unit test
//It is pretty straightforward to mock the ActivatedRoute in the User component test file. All we have to do is to edit the providers list as follows:
beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ UserComponent ],
      imports: [
        RouterTestingModule,
        HttpClientTestingModule
        // ... whatever other module you have
      ],
      providers:
      [
        {
          provide: ActivatedRoute,
          useValue: {
            snapshot: {params: {id: '24fkzrw3487943uf358lovd'}}
          }
        }
      ]
    })
    .compileComponents();
}));
Posted by: Guest on August-26-2021

Code answers related to "NullInjectorError: No provider for ActivatedRoute"

Browse Popular Code Answers by Language