this.service.someMethod
ジャスミンスパイを使用して呼び出されるかどうかをテストしたい。
ソースファイル:
// 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 が呼び出されることが予想されます。