Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: expect(...).toBeObservable is not a function - Jasmine marbles

I am trying to write a basic ngrx effects testing. However I keep getting the error as TypeError: expect(...).toBeObservable is not a function.

This is a new project setup with Angular 7. I had no issues with my previous projects which ran in angular 4.

Initially thought it could be something to do with packages so upgraded all packages to the most latest but no luck yet.

I event tried to test a very simple observable as expect(effects.test$).toBeObservable(5); but it gives the same error. As mentioned in the title I am using jasmine-marbles and the version is 0.4.1.

like image 360
Anand Avatar asked Dec 17 '22 18:12

Anand


1 Answers

You need to init the test scheduler and add matchers in before each or toBeObservable will not be defined:

import { addMatchers, initTestScheduler } from 'jasmine-marbles';

beforeEach(() => {
  ...
  initTestScheduler();
  addMatchers();
});
like image 157
nucleic Avatar answered Jan 06 '23 02:01

nucleic