score:3

This is my solution to mock URLSearchParams

global.URLSearchParams = jest.fn(x => ({
  get: jest.fn(y => x.includes(y) ? 'url does contain get parameter' : 'url does not contain get parameter'),
}));

score:3

Try this!

jest.spyOn(URLSearchParams.prototype, "get").mockReturnValue("some value");

score:11

You have to mock get on URLSearchParams.prototype, like :

jest.spyOn(URLSearchParams.prototype, 'get').mockImplementation((key) => key);

More Query from same tag