@@ -62,7 +62,7 @@ jest.mock('../../../Network/RCTNetworking', () => ({
62
62
if ( name === 'didReceiveNetworkData' ) {
63
63
setImmediate ( ( ) => fn ( [ 1 , mockDataResponse ] ) ) ;
64
64
} else if ( name === 'didCompleteNetworkResponse' ) {
65
- setImmediate ( ( ) => fn ( [ 1 , null ] ) ) ;
65
+ setImmediate ( ( ) => fn ( [ 1 , mockRequestError ] ) ) ;
66
66
} else if ( name === 'didReceiveNetworkResponse' ) {
67
67
setImmediate ( ( ) => fn ( [ 1 , null , mockHeaders ] ) ) ;
68
68
}
@@ -72,9 +72,14 @@ jest.mock('../../../Network/RCTNetworking', () => ({
72
72
} ) ) ;
73
73
74
74
let loadBundleFromServer : ( bundlePathAndQuery : string ) => Promise < void > ;
75
+ const {
76
+ LoadBundleFromServerError,
77
+ LoadBundleFromServerRequestError,
78
+ } = require ( '../loadBundleFromServer' ) ;
75
79
76
80
let mockHeaders : { 'Content-Type' : string } ;
77
81
let mockDataResponse ;
82
+ let mockRequestError = null ;
78
83
79
84
beforeEach ( ( ) => {
80
85
jest . resetModules ( ) ;
@@ -85,15 +90,33 @@ beforeEach(() => {
85
90
test ( 'loadBundleFromServer will throw for JSON responses' , async ( ) => {
86
91
mockHeaders = { 'Content-Type' : 'application/json' } ;
87
92
mockDataResponse = JSON . stringify ( { message : 'Error thrown from Metro' } ) ;
93
+ mockRequestError = null ;
94
+
95
+ try {
96
+ await loadBundleFromServer ( '/Fail.bundle?platform=ios' ) ;
97
+ } catch ( e ) {
98
+ expect ( e ) . toBeInstanceOf ( LoadBundleFromServerError ) ;
99
+ expect ( e . message ) . toBe ( 'Error thrown from Metro' ) ;
100
+ }
101
+ } ) ;
88
102
89
- await expect (
90
- loadBundleFromServer ( '/Fail.bundle?platform=ios' ) ,
91
- ) . rejects . toThrow ( 'Error thrown from Metro' ) ;
103
+ test ( 'loadBundleFromServer will throw LoadBundleFromServerError for request errors' , async ( ) => {
104
+ mockHeaders = { 'Content-Type' : 'application/json' } ;
105
+ mockDataResponse = '' ;
106
+ mockRequestError = 'Some error' ;
107
+
108
+ try {
109
+ await loadBundleFromServer ( '/Fail.bundle?platform=ios' ) ;
110
+ } catch ( e ) {
111
+ expect ( e ) . toBeInstanceOf ( LoadBundleFromServerRequestError ) ;
112
+ expect ( e . message ) . toBe ( 'Some error' ) ;
113
+ }
92
114
} ) ;
93
115
94
116
test ( 'loadBundleFromServer will request a bundle if import bundles are available' , async ( ) => {
95
117
mockDataResponse = '"code";' ;
96
118
mockHeaders = { 'Content-Type' : 'application/javascript' } ;
119
+ mockRequestError = null ;
97
120
98
121
await loadBundleFromServer (
99
122
'/Banana.bundle?platform=ios&dev=true&minify=false&unusedExtraParam=42&modulesOnly=true&runModule=false' ,
@@ -138,6 +161,7 @@ test('loadBundleFromServer will request a bundle if import bundles are available
138
161
test ( 'shows and hides the loading view around a request' , async ( ) => {
139
162
mockDataResponse = '"code";' ;
140
163
mockHeaders = { 'Content-Type' : 'application/javascript' } ;
164
+ mockRequestError = null ;
141
165
142
166
const promise = loadBundleFromServer (
143
167
'/Banana.bundle?platform=ios&dev=true&minify=false&unusedExtraParam=42&modulesOnly=true&runModule=false' ,
@@ -157,6 +181,7 @@ test('shows and hides the loading view around a request', async () => {
157
181
test ( 'shows and hides the loading view around concurrent requests' , async ( ) => {
158
182
mockDataResponse = '"code";' ;
159
183
mockHeaders = { 'Content-Type' : 'application/javascript' } ;
184
+ mockRequestError = null ;
160
185
161
186
const promise1 = loadBundleFromServer (
162
187
'/Banana.bundle?platform=ios&dev=true&minify=false&unusedExtraParam=42&modulesOnly=true&runModule=false' ,
@@ -178,13 +203,15 @@ test('shows and hides the loading view around concurrent requests', async () =>
178
203
test ( 'loadBundleFromServer does not cache errors' , async ( ) => {
179
204
mockHeaders = { 'Content-Type' : 'application/json' } ;
180
205
mockDataResponse = JSON . stringify ( { message : 'Error thrown from Metro' } ) ;
206
+ mockRequestError = null ;
181
207
182
208
await expect (
183
209
loadBundleFromServer ( '/Fail.bundle?platform=ios' ) ,
184
210
) . rejects . toThrow ( ) ;
185
211
186
212
mockDataResponse = '"code";' ;
187
213
mockHeaders = { 'Content-Type' : 'application/javascript' } ;
214
+ mockRequestError = null ;
188
215
189
216
await expect (
190
217
loadBundleFromServer ( '/Fail.bundle?platform=ios' ) ,
@@ -194,6 +221,7 @@ test('loadBundleFromServer does not cache errors', async () => {
194
221
test ( 'loadBundleFromServer caches successful fetches' , async ( ) => {
195
222
mockDataResponse = '"code";' ;
196
223
mockHeaders = { 'Content-Type' : 'application/javascript' } ;
224
+ mockRequestError = null ;
197
225
198
226
const promise1 = loadBundleFromServer (
199
227
'/Banana.bundle?platform=ios&dev=true&minify=false&unusedExtraParam=42&modulesOnly=true&runModule=false' ,
0 commit comments