@@ -153,6 +153,7 @@ describe('internal api', () => {
153
153
} ) ;
154
154
155
155
it ( 'resolves with a dummy token and an error if failed to get a token' , async ( ) => {
156
+ const errorStub = stub ( console , 'error' ) ;
156
157
const appCheck = initializeAppCheck ( app , {
157
158
provider : new ReCaptchaV3Provider ( FAKE_SITE_KEY )
158
159
} ) ;
@@ -162,16 +163,21 @@ describe('internal api', () => {
162
163
const error = new Error ( 'oops, something went wrong' ) ;
163
164
stub ( client , 'exchangeToken' ) . returns ( Promise . reject ( error ) ) ;
164
165
165
- const token = await getToken ( appCheck as AppCheckService ) ;
166
+ const token = await getToken ( appCheck as AppCheckService , false , true ) ;
166
167
167
168
expect ( reCAPTCHASpy ) . to . be . called ;
168
169
expect ( token ) . to . deep . equal ( {
169
170
token : formatDummyToken ( defaultTokenErrorData ) ,
170
171
error
171
172
} ) ;
173
+ expect ( errorStub . args [ 0 ] [ 1 ] . message ) . to . include (
174
+ 'oops, something went wrong'
175
+ ) ;
176
+ errorStub . restore ( ) ;
172
177
} ) ;
173
178
174
179
it ( 'resolves with a dummy token and an error if failed to get a token in debug mode' , async ( ) => {
180
+ const errorStub = stub ( console , 'error' ) ;
175
181
window . FIREBASE_APPCHECK_DEBUG_TOKEN = true ;
176
182
const appCheck = initializeAppCheck ( app , {
177
183
provider : new ReCaptchaV3Provider ( FAKE_SITE_KEY )
@@ -180,28 +186,37 @@ describe('internal api', () => {
180
186
const error = new Error ( 'oops, something went wrong' ) ;
181
187
stub ( client , 'exchangeToken' ) . returns ( Promise . reject ( error ) ) ;
182
188
183
- const token = await getToken ( appCheck as AppCheckService ) ;
189
+ const token = await getToken ( appCheck as AppCheckService , false , true ) ;
184
190
185
191
expect ( token ) . to . deep . equal ( {
186
192
token : formatDummyToken ( defaultTokenErrorData ) ,
187
193
error
188
194
} ) ;
195
+ expect ( errorStub . args [ 0 ] [ 1 ] . message ) . to . include (
196
+ 'oops, something went wrong'
197
+ ) ;
189
198
delete window . FIREBASE_APPCHECK_DEBUG_TOKEN ;
199
+ errorStub . restore ( ) ;
190
200
} ) ;
191
201
192
202
it ( 'resolves with a dummy token and an error if recaptcha failed' , async ( ) => {
203
+ const errorStub = stub ( console , 'error' ) ;
193
204
const appCheck = initializeAppCheck ( app , {
194
205
provider : new ReCaptchaV3Provider ( FAKE_SITE_KEY )
195
206
} ) ;
196
207
197
208
const reCAPTCHASpy = stubGetRecaptchaToken ( '' , false ) ;
198
209
const exchangeTokenStub = stub ( client , 'exchangeToken' ) ;
199
210
200
- const token = await getToken ( appCheck as AppCheckService ) ;
211
+ const token = await getToken ( appCheck as AppCheckService , false , true ) ;
201
212
202
213
expect ( reCAPTCHASpy ) . to . be . called ;
203
214
expect ( exchangeTokenStub ) . to . not . be . called ;
204
215
expect ( token . token ) . to . equal ( formatDummyToken ( defaultTokenErrorData ) ) ;
216
+ expect ( errorStub . args [ 0 ] [ 1 ] . message ) . to . include (
217
+ AppCheckError . RECAPTCHA_ERROR
218
+ ) ;
219
+ errorStub . restore ( ) ;
205
220
} ) ;
206
221
207
222
it ( 'notifies listeners using cached token' , async ( ) => {
0 commit comments