Skip to content

Commit d710ddd

Browse files
committed
add test case
1 parent 4e1dccc commit d710ddd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

test/use-swr-cache.test.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,23 @@ describe('useSWR - cache provider', () => {
198198
it('should support fallback values with custom provider', async () => {
199199
const key = createKey()
200200
function Page() {
201-
const { data } = useSWR(key, async () => {
201+
const { data, isFallback } = useSWR(key, async () => {
202202
await sleep(10)
203203
return 'data'
204204
})
205-
return <>{String(data)}</>
205+
return (
206+
<>
207+
{String(data)},{String(isFallback)}
208+
</>
209+
)
206210
}
207211

208212
renderWithConfig(<Page />, {
209213
provider: () => provider,
210214
fallback: { [key]: 'fallback' }
211215
})
212-
screen.getByText('fallback') // no `undefined`, directly fallback
213-
await screen.findByText('data')
216+
screen.getByText('fallback,true') // no `undefined`, directly fallback
217+
await screen.findByText('data,false')
214218
})
215219

216220
it('should not return the fallback if cached', async () => {

test/use-swr-loading.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('useSWR - loading', () => {
138138
}
139139

140140
renderWithConfig(<Page />)
141-
screen.getByText('data,error,isValidating,mutate')
141+
screen.getByText('data,error,isFallback,isValidating,mutate')
142142
})
143143

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

0 commit comments

Comments
 (0)