Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix for node 20 tests
  • Loading branch information
nikoferro committed May 8, 2024
commit c3f521f5bab33dbca855d996670e9d4f1bebb630
8 changes: 6 additions & 2 deletions src/swapsUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import * as swapsUtil from './swapsUtil';
* @returns An object with a method to clear the mock.
*/
function mockFetch(urlResponseMap: Record<string, any>) {
jest.spyOn(global, 'fetch').mockImplementation(async (url, _) => {
Object.defineProperty(globalThis, 'fetch', {
writable: true,
value: jest.fn(),
});
jest.spyOn(globalThis, 'fetch').mockImplementation(async (url, _) => {
const matchingUrlKey = Object.keys(urlResponseMap).find((key) =>
(url as string).startsWith(key),
);
Expand All @@ -35,7 +39,7 @@ function mockFetch(urlResponseMap: Record<string, any>) {
});

return {
clearMock: () => (global.fetch as jest.Mock).mockRestore(),
clearMock: () => (globalThis.fetch as jest.Mock).mockRestore(),
};
}

Expand Down