@@ -122,6 +122,37 @@ describe('platform_browser/strategies/redirect', () => {
122
122
'auth/argument-error'
123
123
) ;
124
124
} ) ;
125
+
126
+ it ( 'awaits on the auth initialization promise before opening redirect' , async ( ) => {
127
+ // Obtain an auth instance which does not await on the initialization promise.
128
+ const authWithoutAwait : TestAuth = await testAuth (
129
+ resolver ,
130
+ undefined ,
131
+ true
132
+ ) ;
133
+ // completeRedirectFn calls getRedirectResult under the hood.
134
+ const getRedirectResultSpy = sinon . spy (
135
+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
136
+ '_completeRedirectFn'
137
+ ) ;
138
+ const openRedirectSpy = sinon . spy (
139
+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
140
+ '_openRedirect'
141
+ ) ;
142
+ await signInWithRedirect ( authWithoutAwait , provider ) ;
143
+ expect ( getRedirectResultSpy ) . to . have . been . called ;
144
+ expect ( getRedirectResultSpy ) . to . have . been . calledBefore ( openRedirectSpy ) ;
145
+ expect ( getRedirectResultSpy ) . to . have . been . calledWith (
146
+ authWithoutAwait ,
147
+ resolver ,
148
+ true
149
+ ) ;
150
+ expect ( openRedirectSpy ) . to . have . been . calledWith (
151
+ authWithoutAwait ,
152
+ provider ,
153
+ AuthEventType . SIGN_IN_VIA_REDIRECT
154
+ ) ;
155
+ } ) ;
125
156
} ) ;
126
157
127
158
context ( 'linkWithRedirect' , ( ) => {
@@ -159,6 +190,39 @@ describe('platform_browser/strategies/redirect', () => {
159
190
) ;
160
191
} ) ;
161
192
193
+ it ( 'awaits on the auth initialization promise before opening redirect' , async ( ) => {
194
+ // Obtain an auth instance which does not await on the initialization promise.
195
+ const authWithoutAwait : TestAuth = await testAuth (
196
+ resolver ,
197
+ undefined ,
198
+ true
199
+ ) ;
200
+ user = testUser ( authWithoutAwait , 'uid' , 'email' , true ) ;
201
+ // completeRedirectFn calls getRedirectResult under the hood.
202
+ const getRedirectResultSpy = sinon . spy (
203
+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
204
+ '_completeRedirectFn'
205
+ ) ;
206
+ const openRedirectSpy = sinon . spy (
207
+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
208
+ '_openRedirect'
209
+ ) ;
210
+ await authWithoutAwait . _updateCurrentUser ( user ) ;
211
+ await linkWithRedirect ( user , provider , resolver ) ;
212
+ expect ( getRedirectResultSpy ) . to . have . been . called ;
213
+ expect ( getRedirectResultSpy ) . to . have . been . calledBefore ( openRedirectSpy ) ;
214
+ expect ( getRedirectResultSpy ) . to . have . been . calledWith (
215
+ authWithoutAwait ,
216
+ resolver ,
217
+ true
218
+ ) ;
219
+ expect ( openRedirectSpy ) . to . have . been . calledWith (
220
+ authWithoutAwait ,
221
+ provider ,
222
+ AuthEventType . LINK_VIA_REDIRECT
223
+ ) ;
224
+ } ) ;
225
+
162
226
it ( 'errors if no resolver available' , async ( ) => {
163
227
auth . _popupRedirectResolver = null ;
164
228
await expect ( linkWithRedirect ( user , provider ) ) . to . be . rejectedWith (
@@ -236,6 +300,40 @@ describe('platform_browser/strategies/redirect', () => {
236
300
) ;
237
301
} ) ;
238
302
303
+ it ( 'awaits on the auth initialization promise before opening redirect' , async ( ) => {
304
+ // Obtain an auth instance which does not await on the initialization promise.
305
+ const authWithoutAwait : TestAuth = await testAuth (
306
+ resolver ,
307
+ undefined ,
308
+ true
309
+ ) ;
310
+ user = testUser ( authWithoutAwait , 'uid' , 'email' , true ) ;
311
+ // completeRedirectFn calls getRedirectResult under the hood.
312
+ const getRedirectResultSpy = sinon . spy (
313
+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
314
+ '_completeRedirectFn'
315
+ ) ;
316
+ const openRedirectSpy = sinon . spy (
317
+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
318
+ '_openRedirect'
319
+ ) ;
320
+ await authWithoutAwait . _updateCurrentUser ( user ) ;
321
+ await signInWithRedirect ( authWithoutAwait , provider ) ;
322
+ await reauthenticateWithRedirect ( user , provider ) ;
323
+ expect ( getRedirectResultSpy ) . to . have . been . called ;
324
+ expect ( getRedirectResultSpy ) . to . have . been . calledBefore ( openRedirectSpy ) ;
325
+ expect ( getRedirectResultSpy ) . to . have . been . calledWith (
326
+ authWithoutAwait ,
327
+ resolver ,
328
+ true
329
+ ) ;
330
+ expect ( openRedirectSpy ) . to . have . been . calledWith (
331
+ authWithoutAwait ,
332
+ provider ,
333
+ AuthEventType . REAUTH_VIA_REDIRECT
334
+ ) ;
335
+ } ) ;
336
+
239
337
it ( 'errors if no resolver available' , async ( ) => {
240
338
auth . _popupRedirectResolver = null ;
241
339
await expect (
0 commit comments