Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Are spies a bad practice when we are unit testing?

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')
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!