I wrapped the function in the conditional you suggested and added a comment explaining why the test fails in Phantom.js.