| 58 | const promiseFn = jest.fn(() => resolveTo()) |
| 59 | const deferFn = () => resolveTo() |
| 60 | function App() { |
| 61 | const [count, setCount] = React.useState(0) |
| 62 | const { reload } = useAsync({ |
| 63 | promiseFn, |
| 64 | count, |
| 65 | watch: count, |
| 66 | }) |
| 67 | const { run } = useAsync({ |
| 68 | deferFn, |
| 69 | onResolve: reload, |
| 70 | }) |
| 71 | return ( |
| 72 | <div> |
| 73 | <button onClick={() => setCount(n => n + 1)}>inc</button> |
| 74 | <button onClick={() => run()}>run</button> |
| 75 | </div> |
| 76 | ) |
| 77 | } |
| 78 | const { getByText } = render(<App />) |
| 79 | expect(promiseFn).toHaveBeenLastCalledWith(expect.objectContaining({ count: 0 }), abortCtrl) |
| 80 | fireEvent.click(getByText("inc")) |