我的组件使用location.go对网址进行了简单的重写:
import { Location } from '@angular/common';
...
constructor(private location: Location){}
...
this.location.go(`${this.router.url}/${this.projectId}`);
我的单元测试未能说出Expected spy go to have been called
import { Location } from '@angular/common';
...
configureTestSuite(() => {
...
TestBed.configureTestingModule({
...
imports: [..., RouterTestingModule],
providers: [
Location,
],
...
});
loc = TestBed.get(Location);
});
...
describe('Add Project', () => {
it('should add new project', fakeAsync(() => {
...
spyOn(loc, 'go');
...
tick();
expect(loc.go).toHaveBeenCalled();
}));
});