I have an interval set to run a function every 5 minutes: const timer = setInterval(func, TIMEOUT)
This starts when a specific object is created and I use clearInterval
to stop it once a condition is met. This works as expected in practice. However, there are certain tests (using chai and sinon) that result in the creation of the object, though they are not specifically testing the creation of the object. This leads to the creation of the interval, which prevents the tests from every finishing.
I saw in node there is timer.unref()
, which sounds like it would work for me, but in practice since setInverval
in js returns an id, I get a type error Timer.unref is not a function
Is there a way to stop an interval in javascript when the test process ends?
Edit: The creation of the object exists in one package, as part of an API call, and the tests are calling the API from another package, so do not have access to the creation of the object nor the timer. The condition which clears the interval is not (and cannot) be met in the tests.