Я хочу проверить, вызывается ли this.service.someMethod
с помощью jasmine spy.
Исходный файл:
// src.ts
import { Service } from 'some-package';
export class Component {
service = new Service();
callMethod() {
this.service.thatMethod();
}
}
Файл спецификации:
// src.spec.ts
import { Component } from './src';
describe('test', () => {
it('calls thatMethod of service', () => {
let comp = new Component();
spyOn(comp.service, 'thatMethod').and.callThrough();
comp.callMethod();
expect(comp.service.thatMethod).toHaveBeenCalled();
});
});
Выход:
Неудачный тест: ожидается вызов comp.service.thatMethod.
comp.thatMethod();
в вашем тесте не должно бытьcomp.callMethod()
? - person Mike S.   schedule 06.05.2020