@@ -28,11 +28,7 @@ import { TEST_AUTH_DOMAIN, TEST_KEY, testAuth } from '../../test/mock_auth';
28
28
import { AuthEventManager } from '../core/auth/auth_event_manager' ;
29
29
import { OAuthProvider } from '../core/providers/oauth' ;
30
30
import { Auth } from '../model/auth' ;
31
- import {
32
- AuthEvent ,
33
- AuthEventType ,
34
- GapiAuthEvent
35
- } from '../model/popup_redirect' ;
31
+ import { AuthEvent , AuthEventType , GapiAuthEvent } from '../model/popup_redirect' ;
36
32
import * as gapiLoader from './iframe/gapi' ;
37
33
import { BrowserPopupRedirectResolver } from './popup_redirect' ;
38
34
@@ -42,10 +38,23 @@ use(sinonChai);
42
38
describe ( 'src/platform_browser/popup_redirect' , ( ) => {
43
39
let resolver : BrowserPopupRedirectResolver ;
44
40
let auth : Auth ;
41
+ let onIframeMessage : ( event : GapiAuthEvent ) => Promise < void > ;
45
42
46
43
beforeEach ( async ( ) => {
47
44
auth = await testAuth ( ) ;
48
45
resolver = new BrowserPopupRedirectResolver ( ) ;
46
+
47
+ sinon . stub ( gapiLoader , '_loadGapi' ) . returns (
48
+ Promise . resolve ( ( {
49
+ open : ( ) =>
50
+ Promise . resolve ( {
51
+ register : (
52
+ _message : string ,
53
+ cb : ( event : GapiAuthEvent ) => Promise < void >
54
+ ) => ( onIframeMessage = cb )
55
+ } )
56
+ } as unknown ) as gapi . iframes . Context )
57
+ ) ;
49
58
} ) ;
50
59
51
60
afterEach ( ( ) => {
@@ -57,12 +66,13 @@ describe('src/platform_browser/popup_redirect', () => {
57
66
let provider : OAuthProvider ;
58
67
const event = AuthEventType . LINK_VIA_POPUP ;
59
68
60
- beforeEach ( ( ) => {
69
+ beforeEach ( async ( ) => {
61
70
sinon . stub ( window , 'open' ) . callsFake ( url => {
62
71
popupUrl = url ;
63
72
return { } as Window ;
64
73
} ) ;
65
74
provider = new OAuthProvider ( ProviderId . GOOGLE ) ;
75
+ await resolver . _initialize ( auth ) ;
66
76
} ) ;
67
77
68
78
it ( 'builds the correct url' , async ( ) => {
@@ -102,21 +112,6 @@ describe('src/platform_browser/popup_redirect', () => {
102
112
} ) ;
103
113
104
114
context ( '#initialize' , ( ) => {
105
- let onIframeMessage : ( event : GapiAuthEvent ) => Promise < void > ;
106
- beforeEach ( ( ) => {
107
- sinon . stub ( gapiLoader , '_loadGapi' ) . returns (
108
- Promise . resolve ( ( {
109
- open : ( ) =>
110
- Promise . resolve ( {
111
- register : (
112
- _message : string ,
113
- cb : ( event : GapiAuthEvent ) => Promise < void >
114
- ) => ( onIframeMessage = cb )
115
- } )
116
- } as unknown ) as gapi . iframes . Context )
117
- ) ;
118
- } ) ;
119
-
120
115
it ( 'only registers once, returns same event manager' , async ( ) => {
121
116
const manager = await resolver . _initialize ( auth ) ;
122
117
expect ( await resolver . _initialize ( auth ) ) . to . eq ( manager ) ;
0 commit comments