4

I am trying to write unit test for a component that extends a base class.

component.ts

   export class DesktopPresentationAreaComponent extends AbstractPresentationComponent {
            constructor() {
                super(store, webcast);
            }
   }

base class

export abstract class AbstractPresentationComponent {
    constructor(protected store: MainStorageService,
                protected webcast: WebcastService) {
        this.store.get('state').subscribe();
    }

when I run 'ng test' it shows following error.

TypeError: Cannot read property 'subscribe' of undefined in AbstractPresentationComponent

how can I solve this issue?

Pranab V V
  • 1,386
  • 5
  • 27
  • 53

1 Answers1

0

You need to get the 'MainStorageService' instance. Then spyOn for 'store.get('state')'. For e.g.

Get service instance

store = fixture.debugElement.injector.get(MainStorageService);

Spying on get method

spyOn(store, 'get').and.callFake(() => {
    return Observable.from([]);
})
Siddhartha Gupta
  • 1,140
  • 8
  • 13