2020-08-22 13:16:16 +03:00
|
|
|
import { docRegionChain, docRegionObservable, docRegionUnsubscribe } from './observables';
|
|
|
|
|
|
|
|
|
|
describe('observables', () => {
|
|
|
|
|
it('should print 2', (doneFn: DoneFn) => {
|
2021-05-08 16:02:03 +02:00
|
|
|
const consoleSpy = jasmine.createSpyObj<Console>('console', ['log']);
|
|
|
|
|
const observable = docRegionObservable(consoleSpy);
|
2020-08-22 13:16:16 +03:00
|
|
|
observable.subscribe(() => {
|
2021-05-08 16:02:03 +02:00
|
|
|
expect(consoleSpy.log).toHaveBeenCalledTimes(1);
|
|
|
|
|
expect(consoleSpy.log).toHaveBeenCalledWith(2);
|
2020-08-22 13:16:16 +03:00
|
|
|
doneFn();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should close the subscription', () => {
|
|
|
|
|
const subscription = docRegionUnsubscribe();
|
|
|
|
|
expect(subscription.closed).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should chain an observable', (doneFn: DoneFn) => {
|
|
|
|
|
const observable = docRegionChain();
|
|
|
|
|
observable.subscribe(value => {
|
|
|
|
|
expect(value).toBe(4);
|
|
|
|
|
doneFn();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|