node-fetch-cjs icon indicating copy to clipboard operation
node-fetch-cjs copied to clipboard

fetch unstubable

Open tistisman opened this issue 2 years ago • 1 comments

I tried my code

let stubFetch;
const fetch = require("node-fetch-commonjs");
stubFetch = sinon.stub(fetch, "default");
stubFetch.returns(Promise.resolve(new Response(undefined, { status: 200 })));
stubFetch.restore();

it doesn't work.

how to stub your code?

tistisman avatar Oct 18 '22 03:10 tistisman

I haven't worked with sinon yet, but if you get an error or something I think that might be helpful.

After looking at the documentation of sinonjs and the code of node-fetch rq I have two things in mind that could be tried:

  • use sinon.stub(fetch, "fetch"); instead
  • use sinon.stub(fetch); instead

Wissididom avatar Oct 26 '22 07:10 Wissididom