11import { expect } from 'chai' ;
2- import * as Rx from 'rxjs/Rx ' ;
3-
4- const Subscriber = Rx . Subscriber ;
2+ import { SafeSubscriber } from 'rxjs/internal/Subscriber ' ;
3+ import { Subscriber } from 'rxjs' ;
4+ import { rxSubscriber } from 'rxjs/internal/symbol/rxSubscriber' ;
55
66/** @test {Subscriber} */
77describe ( 'Subscriber' , ( ) => {
@@ -20,6 +20,28 @@ describe('Subscriber', () => {
2020 expect ( times ) . to . equal ( 2 ) ;
2121 } ) ;
2222
23+ it ( 'should accept subscribers as a destination if they meet the proper criteria' , ( ) => {
24+ const fakeSubscriber = {
25+ [ rxSubscriber ] ( this : any ) { return this ; } ,
26+ _addParentTeardownLogic ( ) { /* noop */ }
27+ } ;
28+
29+ const subscriber = new Subscriber ( fakeSubscriber as any ) ;
30+ expect ( ( subscriber as any ) . destination ) . to . equal ( fakeSubscriber ) ;
31+ } ) ;
32+
33+ it ( 'should wrap unsafe observers in a safe subscriber' , ( ) => {
34+ const observer = {
35+ next ( x : any ) { /* noop */ } ,
36+ error ( err : any ) { /* noop */ } ,
37+ complete ( ) { /* noop */ }
38+ } ;
39+
40+ const subscriber = new Subscriber ( observer ) ;
41+ expect ( ( subscriber as any ) . destination ) . not . to . equal ( observer ) ;
42+ expect ( ( subscriber as any ) . destination ) . to . be . an . instanceof ( SafeSubscriber ) ;
43+ } ) ;
44+
2345 it ( 'should ignore error messages after unsubscription' , ( ) => {
2446 let times = 0 ;
2547 let errorCalled = false ;
0 commit comments