0
getInactiveTimerTabSynchronizer() {
    return fromEvent(window, 'storage').pipe(
      filter((x: StorageEvent) => {
        return x.key === this.inactivityTabSynchronizerStorageKey;
      }),
      debounceTime(350));
  }

The above code has unit test case as below:

import { Observable, of as observableOf } from 'rxjs';


it(
    'getInactiveTimerTabSynchronizer() function should return an observable that looks for storage events ' +
      'and filters it to only "INACTIVE_TIMER_RESET" keyed events',
    fakeAsync(
      inject([AuthService], (service: AuthService) => {
        spyOn(Observable, 'fromEvent').and.returnValue(
          observableOf({ key: 'INACTIVE_TIMER_RESET' } as StorageEvent, { key: 'SOME_OTHER_KEY' } as StorageEvent)
        );

        let counter = 0;
        service.getInactiveTimerTabSynchronizer().subscribe(x => {
          counter++;
          expect(counter).toBe(1);
        });
        tick(350);
        tick(350);
      })
    )
  );

It was working fine when i had angluar 6 and rxjs 5.5, but after i upgraded to angular 7 and rxjs 6.5 it throws error as:

Argument of type '"fromEvent"' is not assignable to parameter of type '"prototype" | "create" | "if" | "throw"'

Any help for the fix or workaround ?

Ashutosh Singh
  • 269
  • 1
  • 2
  • 9

1 Answers1

0

it has to be spyOn(rxjs, 'fromEvent') now

 import * as rxjs from 'rxjs'
 ...
 spyOn(rxjs, 'fromEvent').and.returnValue(
      observableOf({ key: 'INACTIVE_TIMER_RESET' } as StorageEvent, { key: 'SOME_OTHER_KEY' } as StorageEvent)
    );

because the old way to use fromEvent was

Rx.Observable.fromEvent(input, 'keyup')
Fateh Mohamed
  • 20,445
  • 5
  • 43
  • 52