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

74
Vistas
Mock get call from service in Jasmine test

I am writing a test for my app's login service and would like to mock one of service calls.

This is my code for the test:

describe('LoginService', () => {
  let service: LoginService;
  let mockSupabaseService: SupabaseService;

  beforeEach(() => {
    TestBed.configureTestingModule({});
    mockSupabaseService = TestBed.inject(SupabaseService);
    service = TestBed.inject(LoginService);
    spyOn(mockSupabaseService, 'session').and.returnValue(of(null));
  });

  describe('isLoggedIn()', () => {
    it('should set login form', () => {
      const isLoggedIn = service.isLoggedIn();
      expect(isLoggedIn).toEqual(true);
    });
  });
});

This is the code for the login service I am testing:

export class LoginService {
  constructor(private supabaseService: SupabaseService) {}

  isLoggedIn(): boolean {
    return !!this.supabaseService.session?.user;
  }
}

This is the service I am trying to mock:

export class SupabaseService {
  supabase: SupabaseClient;
  token: string | undefined | null;

  constructor() {
    this.supabase = createClient(environment.supabaseConfig.url, environment.supabaseConfig.key);
  }

  get session(): Session | undefined | null {
    return this.supabase.auth.session();
  }
}

For some reason spyOn(mockSupabaseService, 'session').and.returnValue(of(null)) is flagging as unrecognised (it throws an error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.). But I don't think I am mocking the get call correctly. How do I do that?

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