Skip to content

Commit 6aaa5bd

Browse files
committed
add unit test to ensure useLoadData handles thenable objects as promises
1 parent 01d1dc4 commit 6aaa5bd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

hooks/useLoadData/useLoadData.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,13 @@ describe('useLoadData', () => {
442442
expect(getSuccess).toHaveBeenCalledTimes(2);
443443
expect(getSuccess).toHaveBeenCalledWith('b');
444444
});
445+
446+
it('should treat a thenable object as a Promise', async () => {
447+
const getThenableSuccess = jest.fn(() => ({then: (resolve: any) => resolve(successResult)}));
448+
449+
const {result} = renderHook(() => useLoadData(getThenableSuccess));
450+
expect(result.current.isInProgress).toBe(true);
451+
await waitFor(() => expect(result.current.isInProgress).toBe(false));
452+
expect(result.current.result).toBe(successResult);
453+
});
445454
});

0 commit comments

Comments
 (0)