2019-05-31 11:56:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2020-04-13 19:40:21 -04:00
|
|
|
import {Notification, Observable, of} from 'rxjs';
|
2019-05-31 11:56:07 -04:00
|
|
|
import {dematerialize} from 'rxjs/operators';
|
|
|
|
|
|
|
|
import {asyncTest, ifEnvSupports} from '../test-util';
|
|
|
|
|
|
|
|
const supportNotification = function() {
|
|
|
|
return typeof Notification !== 'undefined';
|
|
|
|
};
|
|
|
|
|
|
|
|
(supportNotification as any).message = 'RxNotification';
|
|
|
|
|
|
|
|
describe('Observable.notification', ifEnvSupports(supportNotification, () => {
|
|
|
|
let log: any[];
|
|
|
|
let observable1: Observable<any>;
|
|
|
|
|
2020-04-13 19:40:21 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
log = [];
|
|
|
|
});
|
2019-05-31 11:56:07 -04:00
|
|
|
|
|
|
|
it('notification func callback should run in the correct zone', () => {
|
|
|
|
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
|
|
|
|
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
|
|
|
|
const error = new Error('test');
|
|
|
|
observable1 = constructorZone1.run(() => {
|
|
|
|
const notifA = new Notification('N' as any, 'A');
|
|
|
|
const notifB = new Notification('N' as any, 'B');
|
|
|
|
const notifE = new Notification('E' as any, void 0, error);
|
2020-04-13 19:40:21 -04:00
|
|
|
const materialized = of(notifA, notifB, notifE as any);
|
2019-05-31 11:56:07 -04:00
|
|
|
return materialized.pipe(dematerialize());
|
|
|
|
});
|
|
|
|
|
|
|
|
subscriptionZone.run(() => {
|
|
|
|
observable1.subscribe(
|
|
|
|
(result: any) => {
|
|
|
|
log.push(result);
|
|
|
|
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
|
|
|
},
|
|
|
|
(err: any) => {
|
|
|
|
log.push(err);
|
|
|
|
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
log.push('completed');
|
|
|
|
expect(Zone.current.name).toEqual(subscriptionZone.name);
|
|
|
|
expect(log).toEqual(['A', 'B', error]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|