Say I have a function that is called on an idle timer:

(defun tmp:create () (mkdir "test"))
(run-with-idle-time 3 nil #'tmp:create)

How can I test that this function works?

Using something like

(ert-deftest async () ""
  (should-not (file-exists-p "test"))
  (sleep-for 4)
  (should (file-exists-p "test")))

doesn't work.

1 Answer 1


Idle timers won't be touched until the call stack has been cleared, so sitting won't actually help, it is only once all execution has stopped with the timer be run, so in your case, the idle timer won't run until 3 seconds of idle time after your whole test has run.

To combat this, you can call ert-run-idle-timers from ert-x.el in your test.

  • That function doesn't seem to exist :( (24.4) Commented Jan 30, 2015 at 1:39
  • 1
    load-library ert-x, sorry didn't specify that. Commented Jan 30, 2015 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.