my.service.tsの内容が以下のような場合において、スパイでhoge()は通せてもsubscribe() に対応するための書き方がわからなかったのでメモ
this.xxxService
.hoge()
.subscribe((val) => {
......
});
import { MyService } from './my.service';
import { xxxService } from './xxx.service';
describe('MyService', () => {
let myService: MyService;
let xxxService: xxxService;
beforeEach(() => {
const xxxServiceSpy = jasmine.createSpyObj('xxxService', ['hoge']);
xxxServiceSpy.hoge.and.returnValue({});
myService = new MyService(xxxServiceSpy);
});
it('should be created', () => {
expect(myService).toBeTruthy();
});
});
returnValue()内を以下のようにすれば、とりあえず通った
import { MyService } from './my.service';
import { xxxService } from './xxx.service';
describe('MyService', () => {
let myService: MyService;
let xxxService: xxxService;
beforeEach(() => {
const xxxServiceSpy = jasmine.createSpyObj('xxxService', ['hoge']);
- xxxServiceSpy.hoge.and.returnValue({});
+ xxxServiceSpy.hoge.and.returnValue({ subscribe: () => {} });
myService = new MyService(xxxServiceSpy);
});
it('should be created', () => {
expect(myService).toBeTruthy();
});
});