Skip to content

Commit 534792b

Browse files
committed
fix test fetch mocking
1 parent ea3f1c1 commit 534792b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

__tests__/jest.setup.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import fetchMock from "jest-fetch-mock";
22

3-
fetchMock.enableMocks();
4-
fetchMock.dontMock();
3+
fetchMock.enableMocks();

__tests__/utils/metadata.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { writeMetadata, readMetadata, metadataFilename } from '../../src/utils/metadata.js';
2+
import { html } from '../test-data/offline-sites/gmod-wiki/recent-changes.js';
3+
import fetchMock from "jest-fetch-mock";
24
import path from 'path';
35
import fs from 'fs';
46
import os from 'os';
@@ -16,19 +18,22 @@ describe('Metadata', () => {
1618
});
1719

1820
it('should be able to write metadata', async () => {
21+
fetchMock.mockResponseOnce(html, { url: 'https://wiki.facepunch.com/gmod/~recentchanges' });
1922
await writeMetadata('https://wiki.facepunch.com/gmod', outputDirectory);
2023

2124
expect(fs.existsSync(path.join(outputDirectory, metadataFilename))).toBeTruthy();
2225
});
2326

2427
it('should be able to write metadata to a non-existing directory', async () => {
28+
fetchMock.mockResponseOnce(html, { url: 'https://wiki.facepunch.com/gmod/~recentchanges' });
2529
const nonExistingDirectory = path.join(outputDirectory, 'non-existing');
2630
await writeMetadata('https://wiki.facepunch.com/gmod', nonExistingDirectory);
2731

2832
expect(fs.existsSync(path.join(nonExistingDirectory, metadataFilename))).toBeTruthy();
2933
});
3034

3135
it('should be able to read metadata', async () => {
36+
fetchMock.mockResponseOnce(html, { url: 'https://wiki.facepunch.com/gmod/~recentchanges' });
3237
await writeMetadata('https://wiki.facepunch.com/gmod', outputDirectory);
3338
const metadata = await readMetadata(outputDirectory);
3439

0 commit comments

Comments
 (0)