@@ -122,6 +122,33 @@ describe('platform_browser/strategies/redirect', () => {
122122 'auth/argument-error'
123123 ) ;
124124 } ) ;
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 ( resolver , undefined , true ) ;
129+ // completeRedirectFn calls getRedirectResult under the hood.
130+ const getRedirectResultSpy = sinon . spy (
131+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
132+ '_completeRedirectFn'
133+ ) ;
134+ const openRedirectSpy = sinon . spy (
135+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
136+ '_openRedirect'
137+ ) ;
138+ await signInWithRedirect ( authWithoutAwait , provider ) ;
139+ expect ( getRedirectResultSpy ) . to . have . been . called ;
140+ expect ( getRedirectResultSpy ) . to . have . been . calledBefore ( openRedirectSpy ) ;
141+ expect ( getRedirectResultSpy ) . to . have . been . calledWith (
142+ authWithoutAwait ,
143+ resolver ,
144+ true
145+ ) ;
146+ expect ( openRedirectSpy ) . to . have . been . calledWith (
147+ authWithoutAwait ,
148+ provider ,
149+ AuthEventType . SIGN_IN_VIA_REDIRECT
150+ ) ;
151+ } ) ;
125152 } ) ;
126153
127154 context ( 'linkWithRedirect' , ( ) => {
@@ -159,6 +186,35 @@ describe('platform_browser/strategies/redirect', () => {
159186 ) ;
160187 } ) ;
161188
189+ it ( 'awaits on the auth initialization promise before opening redirect' , async ( ) => {
190+ // Obtain an auth instance which does not await on the initialization promise.
191+ const authWithoutAwait : TestAuth = await testAuth ( resolver , undefined , true ) ;
192+ user = testUser ( authWithoutAwait , 'uid' , 'email' , true ) ;
193+ // completeRedirectFn calls getRedirectResult under the hood.
194+ const getRedirectResultSpy = sinon . spy (
195+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
196+ '_completeRedirectFn'
197+ ) ;
198+ const openRedirectSpy = sinon . spy (
199+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
200+ '_openRedirect'
201+ ) ;
202+ await authWithoutAwait . _updateCurrentUser ( user ) ;
203+ await linkWithRedirect ( user , provider , resolver ) ;
204+ expect ( getRedirectResultSpy ) . to . have . been . called ;
205+ expect ( getRedirectResultSpy ) . to . have . been . calledBefore ( openRedirectSpy ) ;
206+ expect ( getRedirectResultSpy ) . to . have . been . calledWith (
207+ authWithoutAwait ,
208+ resolver ,
209+ true
210+ ) ;
211+ expect ( openRedirectSpy ) . to . have . been . calledWith (
212+ authWithoutAwait ,
213+ provider ,
214+ AuthEventType . LINK_VIA_REDIRECT
215+ ) ;
216+ } ) ;
217+
162218 it ( 'errors if no resolver available' , async ( ) => {
163219 auth . _popupRedirectResolver = null ;
164220 await expect ( linkWithRedirect ( user , provider ) ) . to . be . rejectedWith (
@@ -236,6 +292,36 @@ describe('platform_browser/strategies/redirect', () => {
236292 ) ;
237293 } ) ;
238294
295+ it ( 'awaits on the auth initialization promise before opening redirect' , async ( ) => {
296+ // Obtain an auth instance which does not await on the initialization promise.
297+ const authWithoutAwait : TestAuth = await testAuth ( resolver , undefined , true ) ;
298+ user = testUser ( authWithoutAwait , 'uid' , 'email' , true ) ;
299+ // completeRedirectFn calls getRedirectResult under the hood.
300+ const getRedirectResultSpy = sinon . spy (
301+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
302+ '_completeRedirectFn'
303+ ) ;
304+ const openRedirectSpy = sinon . spy (
305+ _getInstance < PopupRedirectResolverInternal > ( resolver ) ,
306+ '_openRedirect'
307+ ) ;
308+ await authWithoutAwait . _updateCurrentUser ( user ) ;
309+ await signInWithRedirect ( authWithoutAwait , provider ) ;
310+ await reauthenticateWithRedirect ( user , provider ) ;
311+ expect ( getRedirectResultSpy ) . to . have . been . called ;
312+ expect ( getRedirectResultSpy ) . to . have . been . calledBefore ( openRedirectSpy ) ;
313+ expect ( getRedirectResultSpy ) . to . have . been . calledWith (
314+ authWithoutAwait ,
315+ resolver ,
316+ true
317+ ) ;
318+ expect ( openRedirectSpy ) . to . have . been . calledWith (
319+ authWithoutAwait ,
320+ provider ,
321+ AuthEventType . REAUTH_VIA_REDIRECT
322+ ) ;
323+ } ) ;
324+
239325 it ( 'errors if no resolver available' , async ( ) => {
240326 auth . _popupRedirectResolver = null ;
241327 await expect (
0 commit comments