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

188
Views
La prueba de la unidad Sinon pasa como se esperaba, pero el informe de cobertura muestra que no está cubierto

Dada una clase y un método como:

 export default class Router { constructor(private request: Request) { this.request = request; } public async handle(): Promise<string | undefined> { const pathname = new URL(this.request.url).pathname; if (pathname !== "/requests" && pathname !== "/shipments") { throw new ValidatorError( "ERR_HTTP_PATH", "Not Found", 404, ); ... }

Y una prueba unitaria como:

 Deno.test("router should throw when endpoint is not /requests nor /shipments", async () => { const fakeError = { message: "ERR_HTTP_PATH", cause: "Not Found", status: 404, }; const stub = sinon.stub(Router.prototype, "handle"); stub.rejects(fakeError); const fakeRequest = new Request("http://fakerequest:5000/fakerequest"); const path = new URL(fakeRequest.url).pathname; asserts.assertNotEquals(path, "/requests"); asserts.assertNotEquals(path, "/shipments"); await new Router(fakeRequest) .handle() .catch(err => asserts.assertEquals(err, fakeError)) .finally(() => { asserts.assert(stub.called); stub.restore(); }); });

Esta prueba pasa. Pero, ¿por qué la cobertura de la prueba lo informa como no cubierto?

 12 if (pathname !== "/requests" && pathname !== "/shipments") { 13 | throw new ValidatorError( 14 | "ERR_HTTP_PATH", 15 | "Not Found", 16 | 404, 17 | ); 18 | }

He comprobado que la cobertura no está almacenada en caché internamente y no lo está. Docs en realidad dice que --coverage es una representación precisa de la cobertura del código del motor V8.

¿Qué estoy haciendo mal aquí?

¿Tengo que eliminar necesariamente la clase ValidatorError aunque haya eliminado el método handle para lanzar y reemplazar el comportamiento de la clase?

¿Qué tengo que hacer para que esto quede cubierto en el informe de cobertura?

Gracias

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!