Unit test for a disabled timer

I have a component which regularly calls a function using a timer. From the outside I can configure the rate for that timer.

Testing this is basically trivial: Set up the timer, wait some time, count the calls to the function, and compare to what you expected.

Now there is also the option to disable the timer. How could I test for that?

Waiting for time x is not enough, as the timer may call at x+1.

Is there a better approach?

don't try to test functionality of your language. if js provides you method setInterval then assume it works. what you should test that if your code calls setInterval properly. i don't know much about js testing but if you can, just mock it and check if it was called. if you can't mock it then use one more level of indirection. create your own wrapper for timer - without any logic, just passing invocations. then, in tests, you can check if that wrapper was called or not. i would avoid using wait/sleep in tests