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

233
Vistas
Jasmine testing - Error upon spy definition

I have the following classes

export class Init {
   constructor(url: URL) {}
   
   getClient(url: URL): Client {
    return new Client(url);
  }
}

and the client is defined like

export class Client {
   constructor(readonly url: URL) {}

   foo(s: String): Promise<void> {}

   // many other methods
}

and now I am trying to test this like so - with Jasmine

it('foo should be invoked', done => {
   const init = new Init('test-url');
   
   spyOn(init.getClient,'foo');

   ...
}

On the spy definition I get this error

Argument of type 'string' is not assignable to parameter of type 'never'

Why can I resolve this? Init's getClient method returns a Client object. Shouldn't the spy be able to identify this type?

My end result should look like this

it('foo should be invoked', done => {
   const init = new Init('test-url');
   
   spyOn(init.getClient,'foo');

   expect(initCommand.getClient.foo).toHaveBeenCalledTimes(1);
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can only spyOn public methods. I would do this:

// mock `getClient` object however you like (some examples below)
// Return the object/value right away
spyOn(init, 'getClient').and.returnValue({ foo: (s: string) => Promise.resolve(s) });
// call a fake function every time init.getClient is called
spyOn(init, 'getClient').and.callFake((url) => return {});
about 4 years ago · Juan Pablo Isaza Denunciar
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