Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Apr 15, 2022
1 parent 4e1dccc commit d710ddd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions test/use-swr-cache.test.tsx
Expand Up @@ -198,19 +198,23 @@ describe('useSWR - cache provider', () => {
it('should support fallback values with custom provider', async () => {
const key = createKey()
function Page() {
const { data } = useSWR(key, async () => {
const { data, isFallback } = useSWR(key, async () => {
await sleep(10)
return 'data'
})
return <>{String(data)}</>
return (
<>
{String(data)},{String(isFallback)}
</>
)
}

renderWithConfig(<Page />, {
provider: () => provider,
fallback: { [key]: 'fallback' }
})
screen.getByText('fallback') // no `undefined`, directly fallback
await screen.findByText('data')
screen.getByText('fallback,true') // no `undefined`, directly fallback
await screen.findByText('data,false')
})

it('should not return the fallback if cached', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-loading.test.tsx
Expand Up @@ -138,7 +138,7 @@ describe('useSWR - loading', () => {
}

renderWithConfig(<Page />)
screen.getByText('data,error,isValidating,mutate')
screen.getByText('data,error,isFallback,isValidating,mutate')
})

it('should sync loading states', async () => {
Expand Down

0 comments on commit d710ddd

Please sign in to comment.