Skip to content

Commit

Permalink
test: move fetch mock to file top
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Apr 5, 2023
1 parent 907aada commit f816e9a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/map/utils/read.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, it, vi } from 'vitest';
import { readPB, readQ, nominatimQ } from '../../../src/map/utils/read';

global.fetch = vi.fn();

const input = 'test position';
const result = [{ lat: '1.1', lon: '1.1' }];

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

it('pb markers to readQ', async ({ expect }) => {
global.fetch = vi.fn().mockResolvedValue(mockNominatimResponse(result, true));

// @ts-ignore
fetch.mockResolvedValue(mockNominatimResponse(result, true));

const res = await readPB(
`!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`
);
Expand All @@ -90,7 +93,8 @@ describe.concurrent('read pb', () => {

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

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

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

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

const res = await readQ(input);

Expand Down

0 comments on commit f816e9a

Please sign in to comment.