|
1 |
| -import { act, fireEvent, screen } from '@testing-library/react' |
2 |
| -import React, { Suspense, useState } from 'react' |
| 1 | +import { act, screen } from '@testing-library/react' |
| 2 | +import React, { useState } from 'react' |
3 | 3 | import useSWR from 'swr'
|
4 | 4 | import { createKey, renderWithConfig, nextTick } from './utils'
|
5 | 5 |
|
@@ -33,74 +33,4 @@ describe('useSWR - fetcher', () => {
|
33 | 33 | // Should fetch with the new fetcher.
|
34 | 34 | await screen.findByText('data:bar')
|
35 | 35 | })
|
36 |
| - |
37 |
| - it('should use the latest fetcher reference when the key has been changed', async () => { |
38 |
| - const key = createKey() |
39 |
| - let fetcher = () => 'foo' |
40 |
| - |
41 |
| - function Page() { |
42 |
| - const [prefix, setPrefix] = useState('a') |
43 |
| - const { data } = useSWR(prefix + key, fetcher) |
44 |
| - |
45 |
| - return ( |
46 |
| - <div> |
47 |
| - <p>data:{data}</p> |
48 |
| - <button |
49 |
| - onClick={() => { |
50 |
| - setPrefix('b') |
51 |
| - }} |
52 |
| - > |
53 |
| - mutate |
54 |
| - </button> |
55 |
| - </div> |
56 |
| - ) |
57 |
| - } |
58 |
| - |
59 |
| - renderWithConfig(<Page />) |
60 |
| - await screen.findByText('data:foo') |
61 |
| - |
62 |
| - // Change the fetcher and make sure the ref is updated. |
63 |
| - fetcher = () => 'bar' |
64 |
| - fireEvent.click(screen.getByText('mutate')) |
65 |
| - |
66 |
| - // Should fetch with the new fetcher. |
67 |
| - await screen.findByText('data:bar') |
68 |
| - }) |
69 |
| - |
70 |
| - it('should use the latest fetcher reference with the suspense mode when the key has been changed', async () => { |
71 |
| - const key = createKey() |
72 |
| - let fetcher = () => 'foo' |
73 |
| - |
74 |
| - function Page() { |
75 |
| - const [prefix, setPrefix] = useState('a') |
76 |
| - const { data } = useSWR(prefix + key, fetcher, { suspense: true }) |
77 |
| - |
78 |
| - return ( |
79 |
| - <div> |
80 |
| - <p>data:{data}</p> |
81 |
| - <button |
82 |
| - onClick={() => { |
83 |
| - setPrefix('b') |
84 |
| - }} |
85 |
| - > |
86 |
| - mutate |
87 |
| - </button> |
88 |
| - </div> |
89 |
| - ) |
90 |
| - } |
91 |
| - |
92 |
| - renderWithConfig( |
93 |
| - <Suspense fallback="loading"> |
94 |
| - <Page /> |
95 |
| - </Suspense> |
96 |
| - ) |
97 |
| - await screen.findByText('data:foo') |
98 |
| - |
99 |
| - // Change the fetcher and make sure the ref is updated. |
100 |
| - fetcher = () => 'bar' |
101 |
| - fireEvent.click(screen.getByText('mutate')) |
102 |
| - |
103 |
| - // Should fetch with the new fetcher. |
104 |
| - await screen.findByText('data:bar') |
105 |
| - }) |
106 | 36 | })
|
0 commit comments