I was not very comfortable adding one more arg to the function. 

The problem with the earlier approach was that the mock for window.open or document.getElementById no longer exists inside a setTimeout call.