Skip to content

Commit f816e9a

Browse files
committed
test: move fetch mock to file top
1 parent 907aada commit f816e9a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/map/utils/read.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { describe, it, vi } from 'vitest';
22
import { readPB, readQ, nominatimQ } from '../../../src/map/utils/read';
33

4+
global.fetch = vi.fn();
5+
46
const input = 'test position';
57
const result = [{ lat: '1.1', lon: '1.1' }];
68

@@ -64,8 +66,9 @@ describe.concurrent('read pb', () => {
6466
});
6567

6668
it('pb markers to readQ', async ({ expect }) => {
67-
global.fetch = vi.fn().mockResolvedValue(mockNominatimResponse(result, true));
68-
69+
// @ts-ignore
70+
fetch.mockResolvedValue(mockNominatimResponse(result, true));
71+
6972
const res = await readPB(
7073
`!1m17!1m12!1m3!1d1.1!2d1.1!3d1.1!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m2!1m1!1s${input}!5e0!3m2!1sde!2sde!4v1557583694739!5m2!1sde!2sde`
7174
);
@@ -90,7 +93,8 @@ describe.concurrent('read pb', () => {
9093

9194
describe.concurrent('read query', () => {
9295
it('nominatim request', async ({ expect }) => {
93-
global.fetch = vi.fn().mockResolvedValue(mockNominatimResponse(result, true));
96+
// @ts-ignore
97+
fetch.mockResolvedValue(mockNominatimResponse(result, true));
9498

9599
const res = await readQ(input); // TODO: Mocking requests
96100

@@ -104,7 +108,8 @@ describe.concurrent('read query', () => {
104108
});
105109

106110
it('failing nominatim request', async ({ expect }) => {
107-
global.fetch = vi.fn().mockResolvedValue(mockNominatimResponse(result, false));
111+
// @ts-ignore-next
112+
fetch.mockResolvedValue(mockNominatimResponse(result, false));
108113

109114
const res = await readQ(input);
110115

0 commit comments

Comments
 (0)