我参考了以下链接以获取答案,但是在我的情况下找不到任何可行的解决方案。
错误:(SystemJS)无法解析ActivatedRoute的所有参数:(?,?,?,?,?,?,?,?)
因此,我一直在尝试从提供者中删除Activated Route,但测试平台仍无法通过。它显示
“错误:没有为ActivatedRoute提供程序!”
所以这是我的代码,我想在使用Jasmine的Angular应用程序中运行我的测试平台。
“错误:没有为ActivatedRoute提供程序!”
所以这是我的代码,我想在使用Jasmine的Angular应用程序中运行我的测试平台。
import { ActivatedRoute } from '@angular/router';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule, Routes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
describe('SomeComponent', () => {
let component: SomeComponent;
let fixture: ComponentFixture<SomeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ RouterModule, RouterTestingModule ],
declarations: [ SomeComponent ],
providers: [ ActivatedRoute ],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
获取错误
ActivatedRoute
是由RouterModule
已经定义的提供程序之一,你不应该再次包含它。此外,请注意存在一个名为RouterTestingModule
的模块,可能更适合您的需求。 - jonrsharpe