When we have a situation where the method has no return and its behavior is just calling a dependency according to the input as in the example below, is it bad practice to use spies? Would it be correct to refactor the method to make it return something that represents its behavior?
For better understanding please check following example:
MyClass {
myMethod(input: number) {
if(input > 5) {
this.service1.call('abc');
} else {
this.service1.call('xyz');
}
}
}
// Test
const callSpy = jest.SpyOn(service1, 'call');
const myClass = new MyClass();
myClass.myMethod(1)
expect(callSpy).toBeCalledWith('xyz')