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

238
Views
Prueba de jazmín: error en la definición de espía

tengo las siguientes clases

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

y el cliente se define como

 export class Client { constructor(readonly url: URL) {} foo(s: String): Promise<void> {} // many other methods }

y ahora estoy tratando de probar esto así - con Jasmine

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

En la definición de espía me sale este error

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

¿Por qué puedo resolver esto? El método getClient de Init devuelve un objeto Client . ¿No debería el espía ser capaz de identificar este tipo?

Mi resultado final debería verse así

 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 answers
Answer question

0

Solo puedes spyOn métodos públicos. Yo haría esto:

 // 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 Report
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!