I'm writing unit tests for my Angular app and I'm learning about how to use spies.
Currently, every service that my component uses, I have to write something like this
let fakeMyService = jasmine.createSpyObj('fakeMyService', ['method1', 'method2']);
fakeMyService.method1.and.returnValue(Observable.of());
fakeMyService.method2.and.returnValue(Observable.of());
TestBed.configureTestingModule({
declarations: [MyComponent],
providers: [
{ provide: MyService, useValue: fakeMyService }
]
}).compileComponents();
Although this works, it doesn't seem like the best way to set up my spies. For one, I have to type every single function in MyService that I want to put spies in. Secondly, it's not strongly typed. So if I ever change the name, I won't know immediately and also then, I'll have to update it in every place.
Is there some sort of way where I can just specify the class and it'll automatically just return me a fake class with spies for all the methods?
So something like this
let fakeMyService = jasmine.createSpyObj<MyService>();