(values: string[], intervalMs = 50)
| 2 | |
| 3 | describe('async hook tests', () => { |
| 4 | const useSequence = (values: string[], intervalMs = 50) => { |
| 5 | const [first, ...otherValues] = values |
| 6 | const [value, setValue] = useState(() => first) |
| 7 | const index = useRef(0) |
| 8 | |
| 9 | useEffect(() => { |
| 10 | const interval = setInterval(() => { |
| 11 | setValue(otherValues[index.current++]) |
| 12 | if (index.current >= otherValues.length) { |
| 13 | clearInterval(interval) |
| 14 | } |
| 15 | }, intervalMs) |
| 16 | return () => { |
| 17 | clearInterval(interval) |
| 18 | } |
| 19 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 20 | }, otherValues) |
| 21 | |
| 22 | return value |
| 23 | } |
| 24 | |
| 25 | runForRenderers(['default', 'dom', 'native', 'server/hydrated'], ({ renderHook }) => { |
| 26 | test('should wait for next update', async () => { |
no outgoing calls
no test coverage detected
searching dependent graphs…