File tree 2 files changed +21
-2
lines changed
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 > ) {
2
2
// record promise for test, that resolves before test ends
3
- if ( test ) {
3
+ if ( test && promise instanceof Promise ) {
4
4
// if promise is explicitly awaited, remove it from the list
5
5
promise = promise . finally ( ( ) => {
6
6
const index = test . promises . indexOf ( promise )
Original file line number Diff line number Diff line change @@ -720,6 +720,25 @@ describe('async expect', () => {
720
720
expect ( value ) . toBe ( 1 )
721
721
} )
722
722
} )
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
+ } )
723
742
} )
724
743
725
744
it ( 'compatible with jest' , ( ) => {
You can’t perform that action at this time.
0 commit comments