0

Suppose I have this service (abbreviated of course):

export class TransactionService {
  transactionStatus = new Subject<TransactionStatus[]>();
  transactionStatus$ = this.transactionStatus.asObservable();
}

and setup a test, so that:

const serviceMock = createMock(TransactionsService);

I would like to define its property value, that is transactionStatus$, with the following expression:

serviceMock.transactionStatus$ = of([] as TransactionStatus[]);

But then, Typescript says somthing like: "type Observable<TransactionStatus[]> is missing following properties from type Mock<any, any>". Original text is (in German): "Der Typ "Observable<TransactionStatus[]>" kann dem Typ "Observable<TransactionStatus[]> & Mock<any, any>" nicht zugewiesen werden.".

This will work: (serviceMock.transactionStatus$ as Observable<TransactionStatus[]>) = of([] as TransactionStatus[]);, but I don't want to make all the changes to many other variables in the project with as SomeType just to satisfy this, if there's another option of course and I'm not out of luck.

What I have tried:

And the list goes on, but many of Stackoverflow's answers use jasmine, in my case it's not useful, the members of the project changed to Jest some time ago.

Rick Stanley
  • 498
  • 1
  • 8
  • 14
  • Just learned that I can't add more dependencies to the project either, so libraries like [ng-mocks](https://github.com/ike18t/ng-mocks) are out of the equation. Not that it would be any better than just using `as Observable` too. – Rick Stanley Dec 17 '21 at 03:29

0 Answers0