我正在使用component.ts以下,出现错误
StaticInjectorError(DynamicTestModule)[UploadDocumentsLoginContainerComponent->路由器]:StaticInjectorError(平台:核心)[UploadDocumentsLoginContainerComponent->路由器]:NullInjectorError:路由器没有提供者!
export class UploadDocumentsLoginContainerComponent implements OnInit {
constructor(
private fb: FormBuilder,
private loanStore: Store<LoanState>,
private router: Router,
**private activateRoute: ActivatedRoute,**
private urlProviderService: UrlProviderService
) {
this.activateRoute.queryParams.subscribe(params => {
this.isMyAccountRequest = params[IS_MY_ACCOUNT];
});
}
ngOnInit() {}
//on button click
routeSignin() {
if (this.isMyAccountRequest) {
this.router.navigate(['/home']);
}
}
}
测试用例:
import {
async,
ComponentFixture,
fakeAsync,
TestBed
} from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
describe('UploadDocumentsLoginContainerComponent', () => {
let component: UploadDocumentsLoginContainerComponent;
let fixture: ComponentFixture<UploadDocumentsLoginContainerComponent>;
let router: Router;
beforeEach(async(() => {
return TestBed.configureTestingModule({
declarations: [
UploadDocumentsLoginContainerComponent
],
imports: [
NgbModule,
ReactiveFormsModule,
RouterTestingModule.withRoutes(routes)
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UploadDocumentsLoginContainerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
router = TestBed.get(router);
it('should create', () => {
expect(component).toBeTruthy();
});
it('navigate to "" redirects to /register', () => {
router.navigate(['/register']);
});
});
要解决以上错误,我已在路由器下方添加了。
private router: Router
以后又出现一个错误
UploadDocumentsContainerComponent√应该创造HeadlessChrome 75.0.3770(Windows 10.0.0)错误{“ message”:“ afterAll中引发了错误\ n错误:无法从同步测试中调用Promise.then]
请建议我如何解决此测试用例错误?
我正在使用下方component.ts,得到以下错误StaticInjectorError(DynamicTestModule)[UploadDocumentsLoginContainerComponent->路由器]:StaticInjectorError(平台:核心)[...