Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda