Angular 7 测试:NullInjectorError:ActivatedRoute 没有提供者 [英] Angular 7 Test: NullInjectorError: No provider for ActivatedRoute
本文介绍了Angular 7 测试:NullInjectorError:ActivatedRoute 没有提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,在测试我使用 Angular 7 制作的应用时出现了一些错误.我在 Angular 方面没有太多经验,所以我需要您的帮助+
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!
测试代码是这样的:
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.
丹尼尔
推荐答案
添加如下导入
imports: [
RouterModule.forRoot([]),
...
],
这篇关于Angular 7 测试:NullInjectorError:ActivatedRoute 没有提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文