jeudi 14 mars 2019

How to mock a BehaviorSubject in an Angular Test

I have to rewrite a Angular test because I'm using an BehaviorSubject instead of a simple property now.

Before the BehaviorSubject I mocked the property it like this:

describe('myService', () => {
  let authServiceStub: Partial<UserAuthService>;

  authServiceStub = {
    activeBusinessCase$: 'MOCKBC'
  };

...

But now I get this error message:

Type 'string' is not assignable to type 'BehaviorSubject'.

user-auth.service.ts(32, 10): The expected type comes from property 'activeBusinessCase$' which is declared here on type 'Partial'

How can I mock this BehaviorSubject for my tests to run again?

Aucun commentaire:

Enregistrer un commentaire