@@ -14,6 +14,21 @@ var _typeof =
14
14
: typeof obj ;
15
15
} ;
16
16
17
+ var sessionInitialized = false ;
18
+
19
+ function initSession ( done ) {
20
+ return new Promise ( function promise ( resolve , reject ) {
21
+ if ( sessionInitialized ) {
22
+ return resolve ( ) ;
23
+ }
24
+
25
+ window . Branch . initSession ( ) . then ( function ( ) {
26
+ sessionInitialized = true ;
27
+ resolve ( ) ;
28
+ } ) ;
29
+ } ) ;
30
+ }
31
+
17
32
/**
18
33
* Branch.IO Cordova Plugin Unit-Test
19
34
* ----------------------------------
@@ -67,7 +82,7 @@ exports.defineAutoTests = function() {
67
82
68
83
describe ( "Branch.getLatestReferringParams()" , function ( ) {
69
84
beforeEach ( function ( done ) {
70
- window . Branch . initSession ( ) . then ( function ( ) {
85
+ initSession ( ) . then ( function ( ) {
71
86
done ( ) ;
72
87
} ) ;
73
88
} , 3000 ) ;
@@ -87,7 +102,7 @@ exports.defineAutoTests = function() {
87
102
88
103
describe ( "Branch.getFirstReferringParams()" , function ( ) {
89
104
beforeEach ( function ( done ) {
90
- window . Branch . initSession ( ) . then ( function ( ) {
105
+ initSession ( ) . then ( function ( ) {
91
106
done ( ) ;
92
107
} ) ;
93
108
} , 3000 ) ;
@@ -106,7 +121,7 @@ exports.defineAutoTests = function() {
106
121
107
122
describe ( "Branch.setIdentity()" , function ( ) {
108
123
beforeEach ( function ( done ) {
109
- window . Branch . initSession ( ) . then ( function ( ) {
124
+ initSession ( ) . then ( function ( ) {
110
125
done ( ) ;
111
126
} ) ;
112
127
} , 3000 ) ;
@@ -128,7 +143,7 @@ exports.defineAutoTests = function() {
128
143
var branchUniversalObj ;
129
144
130
145
beforeEach ( function ( done ) {
131
- window . Branch . initSession ( ) . then ( function ( ) {
146
+ initSession ( ) . then ( function ( ) {
132
147
var properties = {
133
148
canonicalIdentifier : "testbed" ,
134
149
title : "testbed" ,
@@ -149,9 +164,7 @@ exports.defineAutoTests = function() {
149
164
"should execute register view" ,
150
165
function ( done ) {
151
166
branchUniversalObj . registerView ( ) . then ( function ( res ) {
152
- expect ( typeof res === "undefined" ? "undefined" : _typeof ( res ) ) . toBe (
153
- "object"
154
- ) ;
167
+ expect ( typeof res ) . not . toBe ( "undefined" ) ;
155
168
done ( ) ;
156
169
} ) ;
157
170
} ,
@@ -192,7 +205,7 @@ exports.defineAutoTests = function() {
192
205
193
206
describe ( "Branch.userCompletedAction()" , function ( ) {
194
207
beforeEach ( function ( done ) {
195
- window . Branch . initSession ( ) . then ( function ( ) {
208
+ initSession ( ) . then ( function ( ) {
196
209
done ( ) ;
197
210
} ) ;
198
211
} , 3000 ) ;
@@ -209,7 +222,7 @@ exports.defineAutoTests = function() {
209
222
210
223
describe ( "Branch.loadRewards()" , function ( ) {
211
224
beforeEach ( function ( done ) {
212
- window . Branch . initSession ( ) . then ( function ( ) {
225
+ initSession ( ) . then ( function ( ) {
213
226
done ( ) ;
214
227
} ) ;
215
228
} , 3000 ) ;
@@ -237,7 +250,7 @@ exports.defineAutoTests = function() {
237
250
238
251
describe ( "Branch.redeemRewards()" , function ( ) {
239
252
beforeEach ( function ( done ) {
240
- window . Branch . initSession ( ) . then ( function ( ) {
253
+ initSession ( ) . then ( function ( ) {
241
254
done ( ) ;
242
255
} ) ;
243
256
} , 3000 ) ;
@@ -265,7 +278,7 @@ exports.defineAutoTests = function() {
265
278
266
279
describe ( "Branch.creditHistory()" , function ( ) {
267
280
beforeEach ( function ( done ) {
268
- window . Branch . initSession ( ) . then ( function ( ) {
281
+ initSession ( ) . then ( function ( ) {
269
282
done ( ) ;
270
283
} ) ;
271
284
} , 3000 ) ;
0 commit comments