@@ -24,16 +24,16 @@ import * as utils from '../utils';
24
24
import { Query , AFUnwrappedDataSnapshot } from '../interfaces' ;
25
25
import { Subscription , Observable , Subject } from 'rxjs' ;
26
26
import { COMMON_CONFIG , ANON_AUTH_CONFIG } from '../test-config' ;
27
- import 'rxjs/add/operator/do' ;
28
- import 'rxjs/add/operator/skip' ;
29
- import 'rxjs/add/operator/take' ;
27
+ import { _do } from 'rxjs/operator/do' ;
28
+ import { skip } from 'rxjs/operator/skip' ;
29
+ import { take } from 'rxjs/operator/take' ;
30
+ import { toPromise } from 'rxjs/operator/toPromise' ;
30
31
31
32
const rootDatabaseUrl = COMMON_CONFIG . databaseURL ;
32
33
33
34
function queryTest ( observable : Observable < any > , subject : Subject < any > , done : any ) {
34
35
let nexted = false ;
35
- observable
36
- . take ( 2 )
36
+ skipAndTake ( observable , 2 )
37
37
. subscribe ( val => {
38
38
if ( ! nexted ) {
39
39
subject . next ( '2' ) ;
@@ -378,7 +378,7 @@ describe('FirebaseListFactory', () => {
378
378
379
379
it ( 'should emit only when the initial data set has been loaded' , ( done : any ) => {
380
380
( < any > questions ) . _ref . set ( [ { initial1 : true } , { initial2 : true } , { initial3 : true } , { initial4 : true } ] )
381
- . then ( ( ) => questions . take ( 1 ) . toPromise ( ) )
381
+ . then ( ( ) => toPromise . call ( skipAndTake ( questions , 1 ) ) )
382
382
. then ( ( val : any [ ] ) => {
383
383
expect ( val . length ) . toBe ( 4 ) ;
384
384
} )
@@ -389,10 +389,8 @@ describe('FirebaseListFactory', () => {
389
389
390
390
391
391
it ( 'should emit a new value when a child moves' , ( done : any ) => {
392
- subscription = questions
393
- . skip ( 2 )
394
- . take ( 1 )
395
- . do ( ( data : any ) => {
392
+ let question = skipAndTake ( questions , 1 , 2 )
393
+ subscription = _do . call ( question , ( data : any ) => {
396
394
expect ( data . length ) . toBe ( 2 ) ;
397
395
expect ( data [ 0 ] . push2 ) . toBe ( true ) ;
398
396
expect ( data [ 1 ] . push1 ) . toBe ( true ) ;
@@ -412,30 +410,26 @@ describe('FirebaseListFactory', () => {
412
410
it ( 'should emit unwrapped data by default' , ( done : any ) => {
413
411
ref . remove ( ( ) => {
414
412
ref . push ( { unwrapped : true } , ( ) => {
415
- subscription = questions
416
- . take ( 1 )
417
- . do ( ( data : any ) => {
418
- expect ( data . length ) . toBe ( 1 ) ;
419
- expect ( data [ 0 ] . unwrapped ) . toBe ( true ) ;
420
- } )
421
- . subscribe ( ( ) => {
422
- done ( ) ;
423
- } , done . fail ) ;
413
+ subscription = _do . call ( skipAndTake ( questions , 1 ) , ( data : any ) => {
414
+ expect ( data . length ) . toBe ( 1 ) ;
415
+ expect ( data [ 0 ] . unwrapped ) . toBe ( true ) ;
416
+ } )
417
+ . subscribe ( ( ) => {
418
+ done ( ) ;
419
+ } , done . fail ) ;
424
420
} ) ;
425
421
} ) ;
426
422
} ) ;
427
423
428
424
429
425
it ( 'should emit snapshots if preserveSnapshot option is true' , ( done : any ) => {
430
426
refSnapshotted . push ( 'hello snapshot!' , ( ) => {
431
- subscription = questionsSnapshotted
432
- . take ( 1 )
433
- . do ( ( data : any ) => {
434
- expect ( data [ 0 ] . val ( ) ) . toEqual ( 'hello snapshot!' ) ;
435
- } )
436
- . subscribe ( ( ) => {
437
- done ( ) ;
438
- } , done . fail ) ;
427
+ subscription = _do . call ( skipAndTake ( questionsSnapshotted , 1 ) , ( data : any ) => {
428
+ expect ( data [ 0 ] . val ( ) ) . toEqual ( 'hello snapshot!' ) ;
429
+ } )
430
+ . subscribe ( ( ) => {
431
+ done ( ) ;
432
+ } , done . fail ) ;
439
433
} ) ;
440
434
} ) ;
441
435
@@ -543,9 +537,13 @@ describe('FirebaseListFactory', () => {
543
537
544
538
expect ( unwrappedValueLol . $key ) . toEqual ( 'key' ) ;
545
539
expect ( unwrappedValueLol . $value ) . toEqual ( 'lol' ) ;
546
- expect ( unwrappedValueLol . $exists ( ) ) . toEqual ( true ) ;
540
+ expect ( unwrappedValueLol . $exists ( ) ) . toEqual ( true ) ;
547
541
} ) ;
548
542
} ) ;
549
543
550
544
} ) ;
551
545
} ) ;
546
+
547
+ function skipAndTake < T > ( obs : Observable < T > , takeCount : number = 1 , skipCount : number = 0 ) {
548
+ return take . call ( skip . call ( obs , skipCount ) , takeCount ) ;
549
+ }
0 commit comments