Skip to content

Commit

Permalink
test: add a test for the behavior of revalidateOnMount when the key h…
Browse files Browse the repository at this point in the history
…as been changed
  • Loading branch information
koba04 committed Feb 8, 2022
1 parent f98da66 commit d0bb061
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/use-swr-integration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ describe('useSWR', () => {
expect(fetch).not.toHaveBeenCalled()
})

it('should call fetch function when revalidateOnMount is false and key has been changed', async () => {
const fetch = jest.fn(() => 'SWR')

function Page() {
const [key, setKey] = useState(createKey())
const { data } = useSWR(key, fetch, {
revalidateOnMount: false
})
return <div onClick={() => setKey(createKey)}>hello,{data}</div>
}

renderWithConfig(<Page />)

await screen.findByText('hello,')
expect(fetch).not.toHaveBeenCalled()

fireEvent.click(screen.getByText('hello,'))

await screen.findByText('hello,SWR')
})

it('should call fetch function when revalidateOnMount is true even if fallbackData is set', async () => {
const fetch = jest.fn(() => 'SWR')

Expand Down

0 comments on commit d0bb061

Please sign in to comment.