Skip to content

Commit

Permalink
add unit test to ensure useLoadData handles thenable objects as promises
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsJPeschel committed Jan 10, 2025
1 parent 01d1dc4 commit 6aaa5bd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hooks/useLoadData/useLoadData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,13 @@ describe('useLoadData', () => {
expect(getSuccess).toHaveBeenCalledTimes(2);
expect(getSuccess).toHaveBeenCalledWith('b');
});

it('should treat a thenable object as a Promise', async () => {
const getThenableSuccess = jest.fn(() => ({then: (resolve: any) => resolve(successResult)}));

const {result} = renderHook(() => useLoadData(getThenableSuccess));
expect(result.current.isInProgress).toBe(true);
await waitFor(() => expect(result.current.isInProgress).toBe(false));
expect(result.current.result).toBe(successResult);
});
});

0 comments on commit 6aaa5bd

Please sign in to comment.