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:
serviceMock.transactionStatus$.mockReturnValue(of([] as TransactionStatus[]));: doesn't work,transactionStatus$is not defined (original: "Cannot read properties of undefined (reading 'mockReturnValue')"), and maybe it won't work, I thinkmockReturnValue()is for functions.- https://stackoverflow.com/a/54502525
- https://stackoverflow.com/a/40240950
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.