jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
882 stars 116 forks source link

TypeError: Unable to parse input as string or Request #192

Closed typhoon2099 closed 3 years ago

typhoon2099 commented 3 years ago

Using fetch with URLs results in the following error. The actual code works, but the mocks fail:

at normalizeRequest (.../node_modules/jest-fetch-mock/src/index.js:129:11)
    at .../node_modules/jest-fetch-mock/src/index.js:76:20
    at finalReturnValue (.../node_modules/jest-mock/build/index.js:480:41)
    at .../node_modules/jest-mock/build/index.js:489:13
    at mockConstructor (.../node_modules/jest-mock/build/index.js:107:19)
    at .../node_modules/jest-fetch-mock/src/index.js:96:29
    at finalReturnValue (.../node_modules/jest-mock/build/index.js:480:41)
    at .../node_modules/jest-mock/build/index.js:489:13
    at fetch (.../node_modules/jest-mock/build/index.js:107:19)
    at API.platformInfringements (.../src/modules/api.js:15:12)
    at Object.beforeEach (.../src/modules/api.test.js:18:28)
    at Object.asyncJestLifecycle (.../node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:53:37)
    at resolve (.../node_modules/jest-jasmine2/build/queueRunner.js:43:12)
    at new Promise (<anonymous>)
    at mapper (.../node_modules/jest-jasmine2/build/queueRunner.js:26:19)
    at promise.then (.../node_modules/jest-jasmine2/build/queueRunner.js:73:41)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Caused by the following:

const endpoint = new URL('https://www.example.com');
return fetch(endpoint);
yinzara commented 3 years ago

Confirmed that is a bug. It accept a URL according to the specification: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch

DougReeder commented 1 year ago

May I suggest it's time to publish version 3.0.4 to NPM?

hbroer commented 1 year ago

is this still not published?

lpommers commented 10 months ago

Would like to see this published as well..