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

342
Vistas
La prueba JEST pasa, pero la cobertura falla

¿Alguien podría ayudarme? Llevo horas con esto y no puedo solucionarlo.

Quiero probar una solicitud con el superagente y verificar si devuelve el código de estado 200. Puse Jest Spy en mi clase para que simule el retorno. La prueba pasa pero mi cobertura no. ¿Qué estoy haciendo mal?

Estoy usando NestJS

Código:

auth.service.ts

 import { Injectable } from '@nestjs/common'; import { Scalar, Query, Args } from '@nestjs/graphql'; import { get } from 'superagent'; @Injectable() @Scalar("JSON", (_) => Object) export class AuthService { @Query((_) => Object) async checkIfUserIsOnline(@Args({ name: "jwtToken", type: () => String }) jwt: string) { const resp = await get(process.env.KEYCLOACK_CHECK_URL).set("Authorization", `Bearer${jwt}`) return { statusCode: resp.statusCode, body: true } } }

auth.service.spec.ts

 import { Test, TestingModule } from '@nestjs/testing'; import { AuthService } from './auth.service'; describe('AuthService', () => { let service: AuthService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ providers: [AuthService], }).compile(); service = module.get<AuthService>(AuthService); }); it('should be defined', () => { expect(service).toBeDefined(); }); test("if user is online", async () => { let spy = jest.spyOn(service, "checkIfUserIsOnline") spy.mockResolvedValue({ statusCode: 200, body: true }) let req = await service.checkIfUserIsOnline("blablabla") expect(req).toStrictEqual({ "body": true, "statusCode": 200 }) }) });

Cobertura:

Informe de cobertura de broma

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