File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1- export function recordAsyncExpect ( test : any , promise : Promise < any > ) {
1+ export function recordAsyncExpect ( test : any , promise : Promise < any > | PromiseLike < any > ) {
22 // record promise for test, that resolves before test ends
3- if ( test ) {
3+ if ( test && promise instanceof Promise ) {
44 // if promise is explicitly awaited, remove it from the list
55 promise = promise . finally ( ( ) => {
66 const index = test . promises . indexOf ( promise )
Original file line number Diff line number Diff line change @@ -720,6 +720,25 @@ describe('async expect', () => {
720720 expect ( value ) . toBe ( 1 )
721721 } )
722722 } )
723+
724+ it ( 'handle thenable objects' , async ( ) => {
725+ await expect ( { then : ( resolve : any ) => resolve ( 0 ) } ) . resolves . toBe ( 0 )
726+ await expect ( { then : ( _ : any , reject : any ) => reject ( 0 ) } ) . rejects . toBe ( 0 )
727+
728+ try {
729+ await expect ( { then : ( resolve : any ) => resolve ( 0 ) } ) . rejects . toBe ( 0 )
730+ }
731+ catch ( error ) {
732+ expect ( error ) . toEqual ( new Error ( 'promise resolved "0" instead of rejecting' ) )
733+ }
734+
735+ try {
736+ await expect ( { then : ( _ : any , reject : any ) => reject ( 0 ) } ) . resolves . toBe ( 0 )
737+ }
738+ catch ( error ) {
739+ expect ( error ) . toEqual ( new Error ( 'promise rejected "0" instead of resolving' ) )
740+ }
741+ } )
723742} )
724743
725744it ( 'compatible with jest' , ( ) => {
You can’t perform that action at this time.
0 commit comments