I am having a service product.service.ts
class ProductService {
public product$: Observable<string> = from(['prod1','prod2','prod3','prod4']);
<other methods goes here...>
}
I want to test the below cases?
prod3
We can achieve this using jasmine.spy
it('should emit respective products'){
const productsSpy = jasmine.createSpy();
service.products$.subscribe(productsSpy);
expect(productsSpy).toHaveBeenCalledTimes(4);
expect(productsSpy.calls.argsFor(2)[0]).toBe('prod3');
}