1
1
import { DatabaseReference } from '../interfaces' ;
2
2
import { AngularFireModule , FirebaseApp , ɵZoneScheduler } from '@angular/fire' ;
3
3
import { AngularFireDatabase , AngularFireDatabaseModule , fromRef } 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 { take } from 'rxjs/operators' ;
7
7
import { TestScheduler } from 'rxjs/testing' ;
@@ -13,7 +13,7 @@ describe('fromRef', () => {
13
13
let ref : ( path : string ) => DatabaseReference ;
14
14
let batch = { } ;
15
15
const items = [ { name : 'one' } , { name : 'two' } , { name : 'three' } ] . map ( item => ( { key : rando ( ) , ...item } ) ) ;
16
- Object . keys ( items ) . forEach ( function ( key ) {
16
+ Object . keys ( items ) . forEach ( ( key ) => {
17
17
const itemValue = items [ key ] ;
18
18
batch [ itemValue . key ] = itemValue ;
19
19
} ) ;
@@ -27,14 +27,13 @@ describe('fromRef', () => {
27
27
AngularFireDatabaseModule
28
28
] ,
29
29
providers : [
30
- { provide : URL , useValue : 'http://localhost:9000' }
30
+ { provide : URL , useValue : 'http://localhost:9000' }
31
31
]
32
32
} ) ;
33
- inject ( [ FirebaseApp , AngularFireDatabase ] , ( app_ : FirebaseApp , db_ : AngularFireDatabase ) => {
34
- app = app_ ;
35
- db = db_ ;
36
- ref = ( path : string ) => db . database . ref ( path ) ;
37
- } ) ( ) ;
33
+
34
+ app = TestBed . inject ( FirebaseApp ) ;
35
+ db = TestBed . inject ( AngularFireDatabase ) ;
36
+ ref = ( path : string ) => db . database . ref ( path ) ;
38
37
} ) ;
39
38
40
39
afterEach ( ( ) => {
@@ -47,7 +46,7 @@ describe('fromRef', () => {
47
46
const obs = fromRef ( itemRef , 'value' ) ;
48
47
let count = 0 ;
49
48
expect ( count ) . toEqual ( 0 ) ;
50
- const sub = obs . subscribe ( change => {
49
+ const sub = obs . subscribe ( ( ) => {
51
50
count = count + 1 ;
52
51
expect ( count ) . toEqual ( 1 ) ;
53
52
sub . unsubscribe ( ) ;
@@ -90,8 +89,8 @@ describe('fromRef', () => {
90
89
91
90
// Error
92
91
const errorObservable = fromRef ( {
93
- once : ( event , snap , err ) => err ( )
94
- } as any ,
92
+ once : ( event , snap , err ) => err ( )
93
+ } as any ,
95
94
'value' ,
96
95
'once' ,
97
96
testScheduler
@@ -120,7 +119,8 @@ describe('fromRef', () => {
120
119
scheduler
121
120
) ;
122
121
completeObservable . subscribe (
123
- ( ) => { } ,
122
+ ( ) => {
123
+ } ,
124
124
( ) => fail ( 'Should not error' ) ,
125
125
( ) => expect ( Zone . current . name ) . toEqual ( 'ExpectedZone' )
126
126
) ;
@@ -133,7 +133,7 @@ describe('fromRef', () => {
133
133
const itemRef = ref ( rando ( ) ) ;
134
134
itemRef . set ( { } ) ;
135
135
const obs = fromRef ( itemRef , 'value' ) ;
136
- const sub = obs . pipe ( take ( 1 ) ) . subscribe ( change => {
136
+ obs . pipe ( take ( 1 ) ) . subscribe ( change => {
137
137
expect ( change . payload . exists ( ) ) . toEqual ( false ) ;
138
138
expect ( change . payload . val ( ) ) . toEqual ( null ) ;
139
139
} ) . add ( done ) ;
@@ -143,15 +143,17 @@ describe('fromRef', () => {
143
143
const itemRef = ref ( rando ( ) ) ;
144
144
itemRef . set ( batch ) ;
145
145
const obs = fromRef ( itemRef , 'value' , 'once' ) ;
146
- obs . subscribe ( change => { } , ( ) => { } , done ) ;
146
+ obs . subscribe ( ( ) => {
147
+ } , ( ) => {
148
+ } , done ) ;
147
149
} ) ;
148
150
149
151
it ( 'it should listen and then unsubscribe' , ( done ) => {
150
152
const itemRef = ref ( rando ( ) ) ;
151
153
itemRef . set ( batch ) ;
152
154
const obs = fromRef ( itemRef , 'value' ) ;
153
155
let count = 0 ;
154
- const sub = obs . subscribe ( change => {
156
+ const sub = obs . subscribe ( ( ) => {
155
157
count = count + 1 ;
156
158
// hard coding count to one will fail if the unsub
157
159
// doesn't actually unsub
@@ -173,7 +175,7 @@ describe('fromRef', () => {
173
175
count = count + 1 ;
174
176
const { type, payload } = change ;
175
177
expect ( type ) . toEqual ( 'child_added' ) ;
176
- expect ( payload . val ( ) ) . toEqual ( batch [ payload . key ! ] ) ;
178
+ expect ( payload . val ( ) ) . toEqual ( batch [ payload . key ] ) ;
177
179
if ( count === items . length ) {
178
180
done ( ) ;
179
181
sub . unsubscribe ( ) ;
@@ -230,7 +232,8 @@ describe('fromRef', () => {
230
232
sub . unsubscribe ( ) ;
231
233
done ( ) ;
232
234
} ) ;
233
- itemRef . child ( key ) . setPriority ( - 100 , ( ) => { } ) ;
235
+ itemRef . child ( key ) . setPriority ( - 100 , ( ) => {
236
+ } ) ;
234
237
} ) ;
235
238
236
239
it ( 'should stream back a value event' , ( done : any ) => {
@@ -252,9 +255,12 @@ describe('fromRef', () => {
252
255
itemRef . set ( batch ) ;
253
256
const query = itemRef . orderByChild ( 'name' ) . equalTo ( items [ 0 ] . name ) ;
254
257
const obs = fromRef ( query , 'value' ) ;
255
- const sub = obs . subscribe ( change => {
256
- let child ;
257
- change . payload . forEach ( snap => { child = snap . val ( ) ; return true ; } ) ;
258
+ obs . subscribe ( change => {
259
+ let child = null ;
260
+ change . payload . forEach ( snap => {
261
+ child = snap . val ( ) ;
262
+ return true ;
263
+ } ) ;
258
264
expect ( child ) . toEqual ( items [ 0 ] ) ;
259
265
done ( ) ;
260
266
} ) ;
0 commit comments