@@ -175,165 +175,4 @@ describe('(unit) src/helper.js', () => {
175
175
} ) ;
176
176
177
177
} ) ;
178
-
179
- describe ( 'Compose resolvers' , ( ) => {
180
- const compositionErr = new Error ( 'composition error' ) ;
181
- const successResolver = createResolver ( ( ) => null , ( ) => null ) ;
182
- const failureResolver = createResolver ( ( ) => { throw compositionErr ; } , ( ) => null ) ;
183
-
184
- it ( 'composed resolvers are chained, and base resolver is called for each' , ( ) => {
185
-
186
- const b = {
187
- resolve : ( ) => { } ,
188
- error : d => compositionErr
189
- } ;
190
-
191
- stub ( b , 'resolve' , b . resolve ) ;
192
-
193
- const base = composable ( b . resolve , b . error ) ;
194
- const comp = base . compose ( {
195
- r1 : ( ) => true ,
196
- r2 : ( ) => true ,
197
- r3 : ( ) => true ,
198
- } ) ;
199
-
200
- return Promise . all ( [
201
-
202
- comp . r1 ( ) . then ( r => {
203
- expect ( b . resolve . calledThrice ) . to . be . true ;
204
- expect ( r ) . to . be . true ;
205
- } ) ,
206
-
207
- comp . r2 ( ) . then ( r => {
208
- expect ( b . resolve . calledThrice ) . to . be . true ;
209
- expect ( r ) . to . be . true ;
210
- } ) ,
211
-
212
- comp . r3 ( ) . then ( r => {
213
- expect ( r ) . to . be . true ;
214
- expect ( b . resolve . calledThrice ) . to . be . true ;
215
- } )
216
-
217
- ] ) ;
218
- } ) ;
219
-
220
- it ( 'when base throws, child is not called ' , ( ) => {
221
-
222
- const b = {
223
- resolve : null ,
224
- error : d => compositionErr
225
- } ;
226
-
227
- const r1 = {
228
- resolve : ( ) => true ,
229
- error : ( ) => compositionErr
230
- } ;
231
-
232
- stub ( b , 'error' , b . error ) ;
233
- stub ( r1 , 'error' , r1 . error ) ;
234
-
235
- const base = composable ( b . resolve , b . error ) ;
236
- const comp = base . compose ( { r1 : r1 } ) ;
237
-
238
- comp . r1 ( )
239
- . catch ( e => {
240
- expect ( b . error . calledOnce ) . to . be . true ;
241
- expect ( r1 . resolve . notCalled ) . to . be . true ;
242
- expect ( r1 . error . notCalled ) . to . be . true ;
243
- expect ( e ) . to . equal ( compositionErr ) ;
244
- } ) ;
245
- } ) ;
246
-
247
- it ( 'when child throws, parent error is called ' , ( ) => {
248
- const b = {
249
- resolve : null ,
250
- error : d => null
251
- } ;
252
-
253
- const r1 = {
254
- resolve : ( ) => true ,
255
- error : ( ) => compositionErr
256
- } ;
257
-
258
- stub ( b , 'error' , b . error ) ;
259
- stub ( r1 , 'error' , r1 . error ) ;
260
-
261
- const base = composable ( b . resolve , b . error ) ;
262
- const comp = base . compose ( { r1 : r1 } ) ;
263
-
264
- comp . r1 ( )
265
- . catch ( e => {
266
- expect ( b . error . calledOnce ) . to . be . true ;
267
- expect ( r1 . error . calledOnce ) . to . be . true ;
268
- expect ( e ) . to . equal ( compositionErr ) ;
269
- } ) ;
270
- } ) ;
271
-
272
- it ( 'composed resolvers with { resolve: resFn, error: resFn } syntax, resolve and bubble errors correctly' , ( ) => {
273
-
274
- const b = {
275
- resolve : ( ) => { } ,
276
- error : d => compositionErr
277
- } ;
278
-
279
- const r1 = {
280
- resolve : ( ) => { throw Error ( 'some other error' ) } ,
281
- error : ( ) => compositionErr } ;
282
-
283
- const r2 = { resolve : ( ) => 'r2Result' , error : ( ) => compositionErr } ;
284
-
285
- stub ( b , 'resolve' , b . resolve ) ;
286
- stub ( r1 , 'error' , r1 . error ) ;
287
- stub ( r1 , 'resolve' , r1 . resolve ) ;
288
- stub ( r2 , 'resolve' , r2 . resolve ) ;
289
- stub ( r2 , 'error' , r2 . error ) ;
290
-
291
- const base = composable ( b . resolve , b . error ) ;
292
- const comp = base . compose ( {
293
- r1 : r1 ,
294
- r2 : r2 ,
295
- } ) ;
296
-
297
- return Promise . all ( [
298
- comp . r1 ( ) . catch ( e => {
299
- expect ( e ) . to . equal ( compositionErr ) ;
300
- } ) ,
301
- comp . r2 ( ) . then ( r => {
302
- expect ( r ) . to . equal ( 'r2Result' ) ;
303
- } ) ,
304
-
305
- ] ) . then ( ( ) => {
306
- expect ( r1 . resolve . calledOnce ) . to . be . true ;
307
- expect ( r1 . error . calledOnce ) . to . be . true ;
308
- expect ( r2 . resolve . calledOnce ) . to . be . true ;
309
- expect ( r2 . error . notCalled ) . to . be . true ;
310
- } ) ;
311
- } ) ;
312
-
313
- it ( 'composed result has correct structure' , ( ) => {
314
-
315
- const b = {
316
- resolve : ( ) => { } ,
317
- error : d => compositionErr
318
- } ;
319
-
320
- stub ( b , 'resolve' , b . resolve ) ;
321
-
322
- const base = composable ( b . resolve , b . error ) ;
323
- const comp = base . compose ( {
324
- r1 : { resolve : ( ) => { throw Error ( 'some other error' ) } , error : ( ) => compositionErr } ,
325
- r2 : { resolve : ( ) => 'r2Result' , error : ( ) => compositionErr } ,
326
- r3 : { } // should we throw an exception since it is not a resolver or createResolver params?
327
- } ) ;
328
-
329
- const composed = { r0 : ( ) => { } , ...comp } ;
330
-
331
- expect ( composed . r0 ) . to . be . a ( typeof Function ) ;
332
- expect ( composed . r1 ) . to . be . a ( typeof Function ) ;
333
- expect ( composed . r2 ) . to . be . a ( typeof Function ) ;
334
- expect ( composed . r3 ) . to . be . a ( typeof Function ) ;
335
-
336
- } ) ;
337
-
338
- } ) ;
339
178
} ) ;
0 commit comments