@@ -37,6 +37,12 @@ import * as sinon from 'sinon';
37
37
import { Component , ComponentType } from '@firebase/component' ;
38
38
import { FirebaseInstallations } from '@firebase/installations-types' ;
39
39
import { openDatabase , APP_NAMESPACE_STORE } from '../src/storage/storage' ;
40
+ import { RemoteConfig } from '@firebase/remote-config-types' ;
41
+ import { RealtimeHandler } from '../src/client/realtime_handler' ;
42
+
43
+ interface RemoteConfigWithHandler extends RemoteConfig {
44
+ _realtimeHandler : RealtimeHandler ;
45
+ }
40
46
41
47
const fakeFirebaseConfig = {
42
48
apiKey : 'api-key' ,
@@ -91,7 +97,7 @@ describe('Remote Config API', () => {
91
97
addObserver : sinon . stub < [ ConfigUpdateObserver ] , Unsubscribe > ( ) . returns ( sinon . stub ( ) ) ,
92
98
removeObserver : sinon . stub < [ ConfigUpdateObserver ] , Unsubscribe > ( ) . returns ( sinon . stub ( ) ) ,
93
99
} ;
94
-
100
+
95
101
_addOrOverwriteComponent (
96
102
app ,
97
103
new Component (
@@ -105,15 +111,14 @@ describe('Remote Config API', () => {
105
111
ComponentType . PUBLIC
106
112
) as any
107
113
) ;
108
- mockRealtimeHandler . addObserver . resetHistory ( ) ;
109
- mockRealtimeHandler . removeObserver . resetHistory ( ) ;
110
-
111
114
} ) ;
112
115
113
116
afterEach ( async ( ) => {
114
117
fetchStub . restore ( ) ;
115
118
await clearDatabase ( ) ;
116
119
await deleteApp ( app ) ;
120
+ mockRealtimeHandler . addObserver . resetHistory ( ) ;
121
+ mockRealtimeHandler . removeObserver . resetHistory ( ) ;
117
122
} ) ;
118
123
119
124
function setFetchResponse ( response : FetchResponse = { status : 200 } ) : void {
@@ -184,11 +189,9 @@ describe('Remote Config API', () => {
184
189
it ( 'should call addObserver on the realtime handler with the correct arguments' , ( ) => {
185
190
const rc = getRemoteConfig ( app ) ;
186
191
const addObserverStub = sinon . stub (
187
- ( rc as any ) . _realtimeHandler ,
192
+ ( rc as unknown as RemoteConfigWithHandler ) . _realtimeHandler ,
188
193
'addObserver'
189
194
) ;
190
- const unsubscribeStub = sinon . stub ( ) ;
191
- addObserverStub . returns ( unsubscribeStub ) ;
192
195
onConfigUpdate ( rc , mockObserver ) ;
193
196
expect ( addObserverStub ) . to . have . been . calledOnceWith ( mockObserver ) ;
194
197
addObserverStub . restore ( ) ;
@@ -197,13 +200,12 @@ describe('Remote Config API', () => {
197
200
it ( 'should return a function that removes the observer' , ( ) => {
198
201
const rc = getRemoteConfig ( app ) ;
199
202
const removeObserverStub = sinon . stub (
200
- ( rc as any ) . _realtimeHandler ,
203
+ ( rc as unknown as RemoteConfigWithHandler ) . _realtimeHandler ,
201
204
'removeObserver'
202
205
) ;
203
206
const unsubscribe = onConfigUpdate ( rc , mockObserver ) ;
204
207
unsubscribe ( ) ;
205
208
expect ( removeObserverStub ) . to . have . been . calledOnceWith ( mockObserver ) ;
206
209
removeObserverStub . restore ( ) ;
207
210
} ) ;
208
-
209
211
} ) ;
0 commit comments