I want to test if this.service.someMethod
is called using jasmine spy.
Source file:
// src.ts
import { Service } from 'some-package';
export class Component {
service = new Service();
callMethod() {
this.service.thatMethod();
}
}
Spec file:
// 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();
});
});
Output:
Failed test: Expected comp.service.thatMethod to have been called.