@@ -391,6 +391,55 @@ describe('moduleMocker', () => {
391391 expect ( fake ( 2 ) ) . toEqual ( 4 ) ;
392392 } ) ;
393393
394+ it ( 'supports mocking resolvable async functions' , ( ) => {
395+ const fn = moduleMocker . fn ( ) ;
396+ fn . mockResolvedValue ( 'abcd' ) ;
397+
398+ const promise = fn ( ) ;
399+
400+ expect ( promise ) . toBeInstanceOf ( Promise ) ;
401+
402+ return promise . then ( value => expect ( value ) . toBe ( 'abcd' ) ) ;
403+ } ) ;
404+
405+ it ( 'supports mocking resolvable async functions only once' , ( ) => {
406+ const fn = moduleMocker . fn ( ) ;
407+ fn . mockResolvedValue ( 'abcd' ) ;
408+ fn . mockResolvedValueOnce ( 'abcde' ) ;
409+
410+ const promise1 = fn ( ) . then ( value => expect ( value ) . toBe ( 'abcde' ) ) ;
411+ const promise2 = fn ( ) . then ( value => expect ( value ) . toBe ( 'abcd' ) ) ;
412+
413+ return Promise . all ( [ promise1 , promise2 ] ) ;
414+ } ) ;
415+
416+ it ( 'supports mocking rejectable async functions' , ( ) => {
417+ const err = new Error ( 'rejected' ) ;
418+ const fn = moduleMocker . fn ( ) ;
419+ fn . mockRejectedValue ( err ) ;
420+
421+ const promise = fn ( ) ;
422+
423+ expect ( promise ) . toBeInstanceOf ( Promise ) ;
424+
425+ return promise . catch ( rejection => expect ( rejection ) . toBe ( err ) ) ;
426+ } ) ;
427+
428+ it ( 'supports mocking rejectable async functions only once' , ( ) => {
429+ const defaultErr = new Error ( 'default rejected' ) ;
430+ const err = new Error ( 'rejected' ) ;
431+ const fn = moduleMocker . fn ( ) ;
432+ fn . mockRejectedValue ( defaultErr ) ;
433+ fn . mockRejectedValueOnce ( err ) ;
434+
435+ const promise1 = fn ( ) . catch ( rejection => expect ( rejection ) . toBe ( err ) ) ;
436+ const promise2 = fn ( ) . catch ( rejection =>
437+ expect ( rejection ) . toBe ( defaultErr ) ,
438+ ) ;
439+
440+ return Promise . all ( [ promise1 , promise2 ] ) ;
441+ } ) ;
442+
394443 describe ( 'timestamps' , ( ) => {
395444 const RealDate = Date ;
396445
0 commit comments