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

79
Views
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
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!