Angular,在单元测试业力/茉莉花中监视Location.go

时间:2020-01-27 15:12:35

标签: angular

我的组件使用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();
  }));
});

0 个答案:

没有答案
相关问题