1
1
import { database } from 'firebase/app' ;
2
2
import { AngularFireModule , FirebaseApp } from '@angular/fire' ;
3
3
import { AngularFireDatabase , AngularFireDatabaseModule , ChildEvent , snapshotChanges , URL } from '../public_api' ;
4
- import { inject , TestBed } from '@angular/core/testing' ;
4
+ import { TestBed } from '@angular/core/testing' ;
5
5
import { COMMON_CONFIG } from '../../test-config' ;
6
6
import { BehaviorSubject } from 'rxjs' ;
7
7
import { skip , switchMap , take } from 'rxjs/operators' ;
@@ -13,10 +13,9 @@ describe('snapshotChanges', () => {
13
13
let db : AngularFireDatabase ;
14
14
let createRef : ( path : string ) => database . Reference ;
15
15
let batch = { } ;
16
- const items = [ { name : 'zero' } , { name : 'one' } , { name : 'two' } ] . map ( ( item , i ) => ( { key : i . toString ( ) , ...item } ) ) ;
17
- Object . keys ( items ) . forEach ( function ( key , i ) {
18
- const itemValue = items [ key ] ;
19
- batch [ i ] = itemValue ;
16
+ const items = [ { name : 'zero' } , { name : 'one' } , { name : 'two' } ] . map ( ( item , i ) => ( { key : i . toString ( ) , ...item } ) ) ;
17
+ Object . keys ( items ) . forEach ( ( key , i ) => {
18
+ batch [ i ] = items [ key ] ;
20
19
} ) ;
21
20
// make batch immutable to preserve integrity
22
21
batch = Object . freeze ( batch ) ;
@@ -31,11 +30,10 @@ describe('snapshotChanges', () => {
31
30
{ provide : URL , useValue : 'http://localhost:9000' }
32
31
]
33
32
} ) ;
34
- inject ( [ FirebaseApp , AngularFireDatabase ] , ( app_ : FirebaseApp , _db : AngularFireDatabase ) => {
35
- app = app_ ;
36
- db = _db ;
37
- createRef = ( path : string ) => db . database . ref ( path ) ;
38
- } ) ( ) ;
33
+
34
+ app = TestBed . inject ( FirebaseApp ) ;
35
+ db = TestBed . inject ( AngularFireDatabase ) ;
36
+ createRef = ( path : string ) => db . database . ref ( path ) ;
39
37
} ) ;
40
38
41
39
afterEach ( ( ) => {
@@ -55,27 +53,29 @@ describe('snapshotChanges', () => {
55
53
it ( 'should listen to all events by default' , ( done ) => {
56
54
const { snapChanges, ref } = prepareSnapshotChanges ( ) ;
57
55
snapChanges . pipe ( take ( 1 ) ) . subscribe ( actions => {
58
- const data = actions . map ( a => a . payload ! . val ( ) ) ;
56
+ const data = actions . map ( a => a . payload . val ( ) ) ;
59
57
expect ( data ) . toEqual ( items ) ;
60
58
} ) . add ( done ) ;
61
59
ref . set ( batch ) ;
62
60
} ) ;
63
61
64
62
it ( 'should handle multiple subscriptions (hot)' , ( done ) => {
65
63
const { snapChanges, ref } = prepareSnapshotChanges ( ) ;
66
- const sub = snapChanges . subscribe ( ( ) => { } ) . add ( done ) ;
64
+ const sub = snapChanges . subscribe ( ( ) => {
65
+ } ) . add ( done ) ;
67
66
snapChanges . pipe ( take ( 1 ) ) . subscribe ( actions => {
68
- const data = actions . map ( a => a . payload ! . val ( ) ) ;
67
+ const data = actions . map ( a => a . payload . val ( ) ) ;
69
68
expect ( data ) . toEqual ( items ) ;
70
69
} ) . add ( sub ) ;
71
70
ref . set ( batch ) ;
72
71
} ) ;
73
72
74
73
it ( 'should handle multiple subscriptions (warm)' , done => {
75
74
const { snapChanges, ref } = prepareSnapshotChanges ( ) ;
76
- snapChanges . pipe ( take ( 1 ) ) . subscribe ( ( ) => { } ) . add ( ( ) => {
75
+ snapChanges . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
76
+ } ) . add ( ( ) => {
77
77
snapChanges . pipe ( take ( 1 ) ) . subscribe ( actions => {
78
- const data = actions . map ( a => a . payload ! . val ( ) ) ;
78
+ const data = actions . map ( a => a . payload . val ( ) ) ;
79
79
expect ( data ) . toEqual ( items ) ;
80
80
} ) . add ( done ) ;
81
81
} ) ;
@@ -85,7 +85,7 @@ describe('snapshotChanges', () => {
85
85
it ( 'should listen to only child_added events' , ( done ) => {
86
86
const { snapChanges, ref } = prepareSnapshotChanges ( { events : [ 'child_added' ] , skipnumber : 0 } ) ;
87
87
snapChanges . pipe ( take ( 1 ) ) . subscribe ( actions => {
88
- const data = actions . map ( a => a . payload ! . val ( ) ) ;
88
+ const data = actions . map ( a => a . payload . val ( ) ) ;
89
89
expect ( data ) . toEqual ( items ) ;
90
90
} ) . add ( done ) ;
91
91
ref . set ( batch ) ;
@@ -118,10 +118,8 @@ describe('snapshotChanges', () => {
118
118
} ) ;
119
119
120
120
it ( 'should handle dynamic queries that return empty sets' , done => {
121
- const ITEMS = 10 ;
122
121
let count = 0 ;
123
- const firstIndex = 0 ;
124
- const namefilter$ = new BehaviorSubject < number | null > ( null ) ;
122
+ const namefilter$ = new BehaviorSubject < number | null > ( null ) ;
125
123
const aref = createRef ( rando ( ) ) ;
126
124
aref . set ( batch ) ;
127
125
namefilter$ . pipe ( switchMap ( name => {
0 commit comments