Raman
Raman

Reputation: 353

getting error Subscribe is not a function in jasmine

I am getting error, subscribe is not a function in angular unit testing

this is the call that I am using in component

this.myService.employees.subscribe(emp => this.emp = emp);

when I create a mock service for this to test the above code getting error.

Can anyone suggest how can I test the above observable.

I want to send mock data when this.myService.employees.subscribe(emp => this.emp = emp); subscribe from component

employees is BehaviorSubject observable

Upvotes: 1

Views: 3690

Answers (1)

satanTime
satanTime

Reputation: 13574

Could you share code how you configure the service in the test?

Usually you should do something like that: https://ng-mocks.sudo.eu/extra/mock-observables

The best option is to use a testing library such as ng-mocks

beforeEach(() => MockBuilder(MyComponent, MyService));

it('test', () => {
  const employees$ = new Subject();
  MockInstance(MyService, 'employees', employees$);

  const fixture = MockRender(MyComponent);
  employees$.next([]);
  // some assertions.
});

Upvotes: 1

Related Questions