Skip to content

Commit

Permalink
Merge pull request #1438 from matkoniecz/feature/dummy-fetch
Browse files Browse the repository at this point in the history
Add mocking of fetch so test will work again.
  • Loading branch information
matkoniecz authored Nov 21, 2024
2 parents 7ab2ede + 7bc6405 commit 2a2c29e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/src/frontend/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@ import { MemoryRouter } from 'react-router-dom';

import { App } from './app';

const originalFetch = global.fetch;

beforeAll(() => {
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
status: 200,
json: () =>
Promise.resolve({
type: "FeatureCollection",
features: [], // Ensure this is an array, even if empty
}),
headers: new Headers(),
redirected: false,
statusText: "OK",
type: "basic",
url: "",
clone: jest.fn(),
body: null,
bodyUsed: false,
text: jest.fn(),
blob: jest.fn(),
formData: jest.fn(),
arrayBuffer: jest.fn(),
})
) as jest.Mock;
});

afterAll(() => {
global.fetch = originalFetch;
});

describe('<App />', () => {
test('renders without exploding', () => {
const div = document.createElement('div');
Expand Down

0 comments on commit 2a2c29e

Please sign in to comment.