Skip to content

Commit 69d8491

Browse files
committed
fix canary ci
1 parent bac7f18 commit 69d8491

File tree

2 files changed

+91
-82
lines changed

2 files changed

+91
-82
lines changed

test/use-swr-promise.test.tsx

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,73 +11,79 @@ import { Suspense } from 'react'
1111
import { ErrorBoundary } from 'react-error-boundary'
1212

1313
describe('useSWR - promise', () => {
14-
it('should allow passing promises as fallback', async () => {
15-
const key = createKey()
14+
itShouldSkipForReactCanary(
15+
'should allow passing promises as fallback',
16+
async () => {
17+
const key = createKey()
1618

17-
const firstRender = [false, undefined] as [boolean, string | undefined]
18-
function Page() {
19-
const { data } = useSWR(key, () => {
20-
return createResponse('new data', { delay: 100 })
21-
})
22-
if (!firstRender[0]) {
23-
firstRender[0] = true
24-
firstRender[1] = data
19+
const firstRender = [false, undefined] as [boolean, string | undefined]
20+
function Page() {
21+
const { data } = useSWR(key, () => {
22+
return createResponse('new data', { delay: 100 })
23+
})
24+
if (!firstRender[0]) {
25+
firstRender[0] = true
26+
firstRender[1] = data
27+
}
28+
return <div>data:{data}</div>
2529
}
26-
return <div>data:{data}</div>
27-
}
2830

29-
const fetchData = createResponse('initial data', { delay: 100 })
31+
const fetchData = createResponse('initial data', { delay: 100 })
3032

31-
renderWithConfig(
32-
<SWRConfig
33-
value={{
34-
fallback: {
35-
[key]: fetchData
36-
}
37-
}}
38-
>
39-
<Page />
40-
</SWRConfig>
41-
)
33+
renderWithConfig(
34+
<SWRConfig
35+
value={{
36+
fallback: {
37+
[key]: fetchData
38+
}
39+
}}
40+
>
41+
<Page />
42+
</SWRConfig>
43+
)
4244

43-
await screen.findByText('data:initial data')
44-
await act(() => sleep(100)) // wait 100ms until the request inside finishes
45-
await screen.findByText('data:new data')
45+
await screen.findByText('data:initial data')
46+
await act(() => sleep(100)) // wait 100ms until the request inside finishes
47+
await screen.findByText('data:new data')
4648

47-
expect(firstRender[1]).toEqual('initial data')
48-
})
49+
expect(firstRender[1]).toEqual('initial data')
50+
}
51+
)
4952

50-
it('should allow passing promises as fallbackData', async () => {
51-
const key = createKey()
53+
itShouldSkipForReactCanary(
54+
'should allow passing promises as fallbackData',
55+
async () => {
56+
const key = createKey()
5257

53-
const fetchData = createResponse('initial data', { delay: 100 })
54-
const firstRender = [false, undefined] as [boolean, string | undefined]
58+
const fetchData = createResponse('initial data', { delay: 100 })
59+
const firstRender = [false, undefined] as [boolean, string | undefined]
5560

56-
function Page() {
57-
const { data } = useSWR(
58-
key,
59-
() => {
60-
return createResponse('new data', { delay: 100 })
61-
},
62-
{
63-
fallbackData: fetchData
61+
function Page() {
62+
const { data } = useSWR(
63+
key,
64+
() => {
65+
return createResponse('new data', { delay: 100 })
66+
},
67+
{
68+
fallbackData: fetchData
69+
}
70+
)
71+
if (!firstRender[0]) {
72+
firstRender[0] = true
73+
firstRender[1] = data
6474
}
65-
)
66-
if (!firstRender[0]) {
67-
firstRender[0] = true
68-
firstRender[1] = data
75+
return <div>data:{data}</div>
6976
}
70-
return <div>data:{data}</div>
71-
}
7277

73-
renderWithConfig(<Page />)
78+
renderWithConfig(<Page />)
7479

75-
await screen.findByText('data:initial data')
76-
await act(() => sleep(100)) // wait 100ms until the request inside finishes
77-
await screen.findByText('data:new data')
80+
await screen.findByText('data:initial data')
81+
await act(() => sleep(100)) // wait 100ms until the request inside finishes
82+
await screen.findByText('data:new data')
7883

79-
expect(firstRender[1]).toEqual('initial data')
80-
})
84+
expect(firstRender[1]).toEqual('initial data')
85+
}
86+
)
8187

8288
itShouldSkipForReactCanary(
8389
'should suspend when resolving the fallback promise',

test/use-swr-suspense.test.tsx

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -366,41 +366,44 @@ describe('useSWR - suspense', () => {
366366
}
367367
)
368368

369-
it('should return `undefined` data for falsy key', async () => {
370-
const key = createKey()
371-
const Section = ({ trigger }: { trigger: boolean }) => {
372-
const { data } = useSWR(
373-
trigger ? key : null,
374-
() => createResponse('SWR'),
375-
{
376-
suspense: true
377-
}
378-
)
379-
return <div>{data || 'empty'}</div>
380-
}
369+
itShouldSkipForReactCanary(
370+
'should return `undefined` data for falsy key',
371+
async () => {
372+
const key = createKey()
373+
const Section = ({ trigger }: { trigger: boolean }) => {
374+
const { data } = useSWR(
375+
trigger ? key : null,
376+
() => createResponse('SWR'),
377+
{
378+
suspense: true
379+
}
380+
)
381+
return <div>{data || 'empty'}</div>
382+
}
381383

382-
const App = () => {
383-
const [trigger, toggle] = useReducer(x => !x, false)
384-
return (
385-
<div>
386-
<button onClick={toggle}>toggle</button>
387-
<Suspense fallback={<div>fallback</div>}>
388-
<Section trigger={trigger} />
389-
</Suspense>
390-
</div>
391-
)
392-
}
384+
const App = () => {
385+
const [trigger, toggle] = useReducer(x => !x, false)
386+
return (
387+
<div>
388+
<button onClick={toggle}>toggle</button>
389+
<Suspense fallback={<div>fallback</div>}>
390+
<Section trigger={trigger} />
391+
</Suspense>
392+
</div>
393+
)
394+
}
393395

394-
renderWithConfig(<App />)
396+
renderWithConfig(<App />)
395397

396-
await screen.findByText('empty')
398+
await screen.findByText('empty')
397399

398-
fireEvent.click(screen.getByRole('button'))
400+
fireEvent.click(screen.getByRole('button'))
399401

400-
screen.getByText('fallback')
402+
screen.getByText('fallback')
401403

402-
await screen.findByText('SWR')
403-
})
404+
await screen.findByText('SWR')
405+
}
406+
)
404407

405408
itShouldSkipForReactCanary(
406409
'should only render fallback once when `keepPreviousData` is set to true',

0 commit comments

Comments
 (0)