I는 다음과 같은 몇 가지 링크가있는 구성 요소를 테스트하기 위해 노력하고있어 : 또한, 이미 this question로보고 시도각도 2 단위 테스트 routerLink 클릭
<a routerLink="/contact">Contact</a>
하지만이 해결되지 않았다 문제. 나는 그 질문 (아래 코드)에 의해 제안 된 솔루션을하려고하면 내가 공급자를 설정하는 트라이 경우
, 나는,이 오류
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [FooterComponent],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
});
describe('...',() => {
it('should navigate to "/contact" when clicking on link', async(inject([Location], (location: Location) => {
fixture.debugElement.query(By.css('.menu')).children[1].nativeElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
console.log(location.path());
});
})));
});
No provider for Location!
가 계속 : [위치] 나는이 오류가 발생합니다 :
spyOn(router, 'navigate');
expect(router.navigate).toHaveBeenCalled();
01 :
Failed: StaticInjectorError[LocationStrategy]:
StaticInjectorError[LocationStrategy]:
NullInjectorError: No provider for LocationStrategy!
나는 다음과 같이 라우터 스파이 시도
하지만 '절대로 호출하지 않음'으로 테스트에 실패합니다.
이 문제를 어떻게 해결할 수 있습니까?
'CommonModule'이 누락되었다고 생각합니다. 사이드 노트는 상상할 수있는 가장 보일러가 많은 상용 코드 중 일부입니다. –
@AluanHaddad 오류를 해결했지만 location.path() 로그는 예상 URL 대신 항상 공백으로 표시합니다. – celsomtrindade
나는 그것에 대해 전혀 모른다. 그래도 설정이 의심스러워 보입니다. 살펴 봐야 할 다양한 동기 및 비동기 초기화 로직이 있습니다. –