Skip to content

Commit

Permalink
fix(use-dataloader): avoid exception when options are not defined (#148)
Browse files Browse the repository at this point in the history
* fix(use-dataloader): avoid exception when options are not defined

* test: add bug reproduction
  • Loading branch information
chambo-e authored May 3, 2021
1 parent b84d555 commit 347e539
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/use-dataloader/src/__tests__/useDataLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ const wrapper = ({ children }) => (
)

describe('useDataLoader', () => {
test('should render correctly without options', async () => {
const { result, waitForNextUpdate, rerender } = renderHook(
props => useDataLoader(props.key, props.method),
{
wrapper,
initialProps,
},
)
expect(result.current.data).toBe(undefined)
expect(result.current.isLoading).toBe(true)
rerender()
await waitForNextUpdate()
expect(result.current.data).toBe(true)
expect(result.current.isSuccess).toBe(true)
expect(result.current.isLoading).toBe(false)
})

test('should render correctly with enabled true', async () => {
const { result, waitForNextUpdate, rerender } = renderHook(
props => useDataLoader(props.key, props.method, props.config),
Expand Down
2 changes: 1 addition & 1 deletion packages/use-dataloader/src/useDataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const useDataLoader = (
enabled = true,
reloadOnKeyChange = true,
keepPreviousData = true,
},
} = {},
) => {
const {
addCachedData,
Expand Down

0 comments on commit 347e539

Please sign in to comment.