@@ -60,10 +60,10 @@ describe('api/_performApiRequest', () => {
60
60
} ) ;
61
61
62
62
context ( 'with regular requests' , ( ) => {
63
- beforeEach ( mockFetch . setUp ) ;
64
63
afterEach ( mockFetch . tearDown ) ;
65
64
66
65
it ( 'should set the correct request, method and HTTP Headers' , async ( ) => {
66
+ mockFetch . setUp ( ) ;
67
67
const mock = mockEndpoint ( Endpoint . SIGN_UP , serverResponse ) ;
68
68
const response = await _performApiRequest <
69
69
typeof request ,
@@ -82,6 +82,7 @@ describe('api/_performApiRequest', () => {
82
82
} ) ;
83
83
84
84
it ( 'should set the device language if available' , async ( ) => {
85
+ mockFetch . setUp ( ) ;
85
86
auth . languageCode = 'jp' ;
86
87
const mock = mockEndpoint ( Endpoint . SIGN_UP , serverResponse ) ;
87
88
const response = await _performApiRequest <
@@ -95,6 +96,7 @@ describe('api/_performApiRequest', () => {
95
96
} ) ;
96
97
97
98
it ( 'should include whatever headers the auth impl attaches' , async ( ) => {
99
+ mockFetch . setUp ( ) ;
98
100
sinon . stub ( auth , '_getAdditionalHeaders' ) . returns (
99
101
Promise . resolve ( {
100
102
'look-at-me-im-a-header' : 'header-value' ,
@@ -118,6 +120,7 @@ describe('api/_performApiRequest', () => {
118
120
} ) ;
119
121
120
122
it ( 'should set the framework in clientVersion if logged' , async ( ) => {
123
+ mockFetch . setUp ( ) ;
121
124
auth . _logFramework ( 'Mythical' ) ;
122
125
const mock = mockEndpoint ( Endpoint . SIGN_UP , serverResponse ) ;
123
126
const response = await _performApiRequest <
@@ -143,6 +146,7 @@ describe('api/_performApiRequest', () => {
143
146
} ) ;
144
147
145
148
it ( 'should translate server errors to auth errors' , async ( ) => {
149
+ mockFetch . setUp ( ) ;
146
150
const mock = mockEndpoint (
147
151
Endpoint . SIGN_UP ,
148
152
{
@@ -172,6 +176,7 @@ describe('api/_performApiRequest', () => {
172
176
} ) ;
173
177
174
178
it ( 'should translate server success with errorMessage into auth error' , async ( ) => {
179
+ mockFetch . setUp ( ) ;
175
180
const response = {
176
181
errorMessage : ServerError . FEDERATED_USER_ID_ALREADY_LINKED ,
177
182
idToken : 'foo-bar'
@@ -193,6 +198,7 @@ describe('api/_performApiRequest', () => {
193
198
} ) ;
194
199
195
200
it ( 'should translate complex server errors to auth errors' , async ( ) => {
201
+ mockFetch . setUp ( ) ;
196
202
const mock = mockEndpoint (
197
203
Endpoint . SIGN_UP ,
198
204
{
@@ -222,6 +228,7 @@ describe('api/_performApiRequest', () => {
222
228
} ) ;
223
229
224
230
it ( 'should pass through server messages if applicable' , async ( ) => {
231
+ mockFetch . setUp ( ) ;
225
232
mockEndpoint (
226
233
Endpoint . SIGN_UP ,
227
234
{
@@ -247,6 +254,7 @@ describe('api/_performApiRequest', () => {
247
254
} ) ;
248
255
249
256
it ( 'should handle unknown server errors' , async ( ) => {
257
+ mockFetch . setUp ( ) ;
250
258
const mock = mockEndpoint (
251
259
Endpoint . SIGN_UP ,
252
260
{
@@ -276,6 +284,7 @@ describe('api/_performApiRequest', () => {
276
284
} ) ;
277
285
278
286
it ( 'should support custom error handling per endpoint' , async ( ) => {
287
+ mockFetch . setUp ( ) ;
279
288
const mock = mockEndpoint (
280
289
Endpoint . SIGN_UP ,
281
290
{
@@ -306,6 +315,22 @@ describe('api/_performApiRequest', () => {
306
315
) ;
307
316
expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
308
317
} ) ;
318
+
319
+ it ( 'should handle non-FirebaseErrors' , async ( ) => {
320
+ mockFetch . setUpWithOverride ( ( ) => {
321
+ return new Promise < never > ( ( _ , reject ) => reject ( new Error ( 'error' ) ) ) ;
322
+ } ) ;
323
+ const promise = _performApiRequest < typeof request , never > (
324
+ auth ,
325
+ HttpMethod . POST ,
326
+ Endpoint . SIGN_UP ,
327
+ request
328
+ ) ;
329
+ await expect ( promise ) . to . be . rejectedWith (
330
+ FirebaseError ,
331
+ 'auth/internal-error'
332
+ ) ;
333
+ } ) ;
309
334
} ) ;
310
335
311
336
context ( 'with network issues' , ( ) => {
@@ -345,22 +370,6 @@ describe('api/_performApiRequest', () => {
345
370
expect ( clock . clearTimeout ) . to . have . been . called ;
346
371
clock . restore ( ) ;
347
372
} ) ;
348
-
349
- it ( 'should handle failures' , async ( ) => {
350
- mockFetch . setUpWithOverride ( ( ) => {
351
- return new Promise < never > ( ( _ , reject ) => reject ( new Error ( 'error' ) ) ) ;
352
- } ) ;
353
- const promise = _performApiRequest < typeof request , never > (
354
- auth ,
355
- HttpMethod . POST ,
356
- Endpoint . SIGN_UP ,
357
- request
358
- ) ;
359
- await expect ( promise ) . to . be . rejectedWith (
360
- FirebaseError ,
361
- 'auth/internal-error'
362
- ) ;
363
- } ) ;
364
373
} ) ;
365
374
366
375
context ( 'edgcase error mapping' , ( ) => {
0 commit comments