1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Angular 7 Test: NullInjectorError: No provider for ActivatedRoute

Discussão em 'Angular' iniciado por Daniel, Outubro 16, 2024 às 08:22.

  1. Daniel

    Daniel Guest

    Hi have some error with testing my App made with Angular 7. I do not have much experience in angular, so I would need your help+

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


    the testing code is like this:

    import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
    import { BeerDetailsComponent } from './beer-details.component';
    import {
    HttpClientTestingModule,
    HttpTestingController
    } from '@angular/common/http/testing';

    describe('BeerDetailsComponent', () => {
    let component: BeerDetailsComponent;
    let fixture: ComponentFixture<BeerDetailsComponent>;

    beforeEach(async(() => {
    TestBed.configureTestingModule({
    imports: [HttpClientTestingModule],
    declarations: [ BeerDetailsComponent ]
    })
    .compileComponents();
    }));

    beforeEach(() => {
    fixture = TestBed.createComponent(BeerDetailsComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
    });

    it('should create',
    inject(
    [HttpTestingController],
    () => {
    expect(component).toBeTruthy();
    }
    )
    )
    });


    I really can't find any solution.

    Daniele

    Continue reading...

Compartilhe esta Página