1
1
import { 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' ;
5
5
6
6
/** @test {Subscriber} */
7
7
describe ( 'Subscriber' , ( ) => {
@@ -20,6 +20,28 @@ describe('Subscriber', () => {
20
20
expect ( times ) . to . equal ( 2 ) ;
21
21
} ) ;
22
22
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
+
23
45
it ( 'should ignore error messages after unsubscription' , ( ) => {
24
46
let times = 0 ;
25
47
let errorCalled = false ;
0 commit comments