|
1 | 1 | import fetch from 'jest-fetch-mock'; |
2 | 2 | import { renderHook } from '@testing-library/react-hooks'; |
3 | | -import useStacApi from './useStacApi'; |
4 | 3 | import useCollections from './useCollections'; |
| 4 | +import wrapper from './wrapper'; |
5 | 5 |
|
6 | 6 | describe('useStacApi', () => { |
7 | 7 | beforeEach(() => fetch.resetMocks()); |
8 | | - |
9 | 8 | it('initilises StacAPI', async () => { |
10 | | - fetch.mockResponseOnce(JSON.stringify({ links: [] }), { url: 'https://fake-stac-api.net' }); |
11 | | - const { result: stacApiResult, waitForNextUpdate: waitForApiUpdate } = renderHook( |
12 | | - () => useStacApi('https://fake-stac-api.net') |
13 | | - ); |
14 | | - await waitForApiUpdate(); |
| 9 | + fetch |
| 10 | + .mockResponseOnce(JSON.stringify({ links: [] }), { url: 'https://fake-stac-api.net' }) |
| 11 | + .mockResponseOnce(JSON.stringify({ data: '12345' })); |
15 | 12 |
|
16 | | - fetch.mockResponseOnce(JSON.stringify({ data: '12345' })); |
17 | | - const { waitForNextUpdate: waitForCollectionsUpdate } = renderHook( |
18 | | - () => useCollections(stacApiResult.current.stacApi) |
| 13 | + const { waitForNextUpdate } = renderHook( |
| 14 | + () => useCollections(), |
| 15 | + { wrapper } |
19 | 16 | ); |
20 | | - await waitForCollectionsUpdate(); |
| 17 | + await waitForNextUpdate(); |
| 18 | + await waitForNextUpdate(); |
21 | 19 | expect(fetch.mock.calls[1][0]).toEqual('https://fake-stac-api.net/collections'); |
22 | 20 | }); |
23 | 21 |
|
24 | 22 | it('initilises StacAPI with redirect URL', async () => { |
25 | | - fetch.mockResponseOnce(JSON.stringify({ links: [] }), { url: 'https://fake-stac-api.net/redirect/' }); |
26 | | - const { result: stacApiResult, waitForNextUpdate: waitForApiUpdate } = renderHook( |
27 | | - () => useStacApi('https://fake-stac-api.net') |
28 | | - ); |
29 | | - await waitForApiUpdate(); |
| 23 | + fetch |
| 24 | + .mockResponseOnce(JSON.stringify({ links: [] }), { url: 'https://fake-stac-api.net/redirect/' }) |
| 25 | + .mockResponseOnce(JSON.stringify({ data: '12345' })); |
30 | 26 |
|
31 | | - fetch.mockResponseOnce(JSON.stringify({ data: '12345' })); |
32 | | - const { waitForNextUpdate: waitForCollectionsUpdate } = renderHook( |
33 | | - () => useCollections(stacApiResult.current.stacApi) |
| 27 | + const { waitForNextUpdate } = renderHook( |
| 28 | + () => useCollections(), |
| 29 | + { wrapper } |
34 | 30 | ); |
35 | | - await waitForCollectionsUpdate(); |
| 31 | + await waitForNextUpdate(); |
| 32 | + await waitForNextUpdate(); |
36 | 33 | expect(fetch.mock.calls[1][0]).toEqual('https://fake-stac-api.net/redirect/collections'); |
37 | 34 | }); |
38 | 35 | }); |
0 commit comments