0

When I use sinon fakeTimer with supertest, it leads to an error Error: socket hang up. Why and how to fix it, pls help ?

  • Can you share the code? – Jim Aug 20 '18 at 21:23
  • The function for your "it" block can take a parameter normally called "done". You then invoke it, `done()`, when you want to end the test. This might help you. – Jim Aug 20 '18 at 21:24

1 Answers1

1

It a very old question and I hope you found the answer, but maybe my answer helps to others.

Fake only the necessary "functions" with sinon. useFakeTimers fake setInterval and setImmediate js functiony by default so it cause the hang up.

Setup the toFake parameters of the useFakeTimers options

const sandbox = createSandbox();
sandbox.useFakeTimers({
    now: currentDate.getTime(),
    toFake: ['Date']
  });
// ... tests
sandbox.restore();

https://sinonjs.org/releases/v6.2.0/fake-timers/

Kiss Robert
  • 201
  • 3
  • 7