Skip to content

Commit

Permalink
fix(util): mock fetch should get url from req body
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Sep 2, 2024
1 parent 93fa2c4 commit fca0b32
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/util/__tests__/archiveUrlsFromText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ describe('archiveUrlsFromText', () => {
beforeAll(() => {
// Spy on and mock the global fetch function
mockedFetch = jest.spyOn(global, 'fetch');
mockedFetch.mockImplementation(async (url) => {
mockedFetch.mockImplementation(async (url, reqInit) => {
// Make Tyepscript happy
if (typeof url !== 'string')
throw new Error(
'Fetch with non-string URL is not implemented in unit test'
);

// Extract URL to archive from fetched URL
const params = new URL(url).searchParams;
const urlToArchive = params.get('url');
const urlToArchive = (reqInit?.body as FormData).get('url');

return {
json: async () => ({ job_id: '123', url: urlToArchive }),
Expand Down

0 comments on commit fca0b32

Please sign in to comment.