@@ -151,6 +151,8 @@ describe('completeOAuthFlow', () => {
151
151
token_type : 'token_type' ,
152
152
expires_in : 'expires_in' ,
153
153
} ;
154
+ const executionOrder : string [ ] = [ ] ;
155
+
154
156
mockValidateState . mockReturnValueOnce ( 'myState-valid_state' ) ;
155
157
( oAuthStore . loadPKCE as jest . Mock ) . mockResolvedValueOnce ( 'pkce23234a' ) ;
156
158
const mockJsonMethod = jest . fn ( ( ) => Promise . resolve ( expectedTokens ) ) ;
@@ -162,6 +164,12 @@ describe('completeOAuthFlow', () => {
162
164
mockFetch . mockResolvedValueOnce ( {
163
165
json : mockJsonMethod ,
164
166
} ) ;
167
+ mockReplaceState . mockImplementation ( ( ..._args ) =>
168
+ executionOrder . push ( 'replaceState' ) ,
169
+ ) ;
170
+ mockHubDispatch . mockImplementation ( ( ) =>
171
+ executionOrder . push ( 'hubDispatch' ) ,
172
+ ) ;
165
173
166
174
await completeOAuthFlow ( testInput ) ;
167
175
@@ -180,17 +188,27 @@ describe('completeOAuthFlow', () => {
180
188
TokenType : expectedTokens . token_type ,
181
189
ExpiresIn : expectedTokens . expires_in ,
182
190
} ) ;
191
+
192
+ expect ( oAuthStore . clearOAuthData ) . toHaveBeenCalledTimes ( 1 ) ;
193
+ expect ( oAuthStore . storeOAuthSignIn ) . toHaveBeenCalledWith ( true , undefined ) ;
194
+
195
+ expect ( mockResolveAndClearInflightPromises ) . toHaveBeenCalledTimes ( 1 ) ;
196
+
183
197
expect ( mockReplaceState ) . toHaveBeenCalledWith (
184
198
'http://localhost:3000/?code=aaaa-111-222&state=aaaaa' ,
185
199
'' ,
186
200
testInput . redirectUri ,
187
201
) ;
188
202
189
- expect ( oAuthStore . clearOAuthData ) . toHaveBeenCalledTimes ( 1 ) ;
190
- expect ( oAuthStore . storeOAuthSignIn ) . toHaveBeenCalledWith ( true , undefined ) ;
191
-
192
203
expect ( mockHubDispatch ) . toHaveBeenCalledTimes ( 3 ) ;
193
- expect ( mockResolveAndClearInflightPromises ) . toHaveBeenCalledTimes ( 1 ) ;
204
+
205
+ // Verify we replace browser tab location before dispatching hub events
206
+ expect ( executionOrder ) . toEqual ( [
207
+ 'replaceState' ,
208
+ 'hubDispatch' ,
209
+ 'hubDispatch' ,
210
+ 'hubDispatch' ,
211
+ ] ) ;
194
212
} ) ;
195
213
196
214
it ( 'throws when `fetch` call resolves error' , async ( ) => {
0 commit comments