setTimeout() not working if yasmine directly execute from PhantomJS

397 views
Skip to first unread message

Tor...@robitzki.de

unread,
Nov 2, 2012, 12:46:21 PM11/2/12
to Jasmine
Hello,
first of all thank you to all who contributed to this very helpful
library!

Currently I'm trying to add unit tests for my JavaScript and
CoffeeScript code to a rails (3.2.8) project. I've found a lot of
working solutions, but all of them seemed a little bit to much for
what I was looking for. The workflow that I have in mind is like this:
I add a new source file (.js or .coffee) to the rails /app/assets/
javascripts and tests for the functions to /test/scripts. This should
be enough to run "rake test:scripts" in the shell and to run all
tests.

As I'm running final unit tests in a production environment, I've
tried to keep the dependencies as little as possible. I found phantom-
jasmine on github. I toke that solution and removed the need for an
extra html file and came up with a solution that defines a rake task,
that creates two javascript files: run_jasmin_tests.js and
jasmin_assets.js.

run_jasmin_tests.js contains calls to phantom.injectJs() to load
jasmine, the console-runner.js from Joshua Carver, all files under /
test/scripts and a call to jasmine.getEnv().execute();. There is no
WebPage.open() involved.

I had trouble executing the test suits. The call to
jasmine.getEnv().execute() didn't executed the runner
finishCallback(). I've boiled this down to
jasmine.Queue.prototype.next_ where a next call to next_ is generated
in a callback passed to self.env.setTimeout(). That call back is never
executed. I've hacked this to make it work, but this doesn't looks
like a viable solution to me:

jasmine.Env.prototype.setTimeout = function(f,t){ f();}

Is there a better solution to my problem? Any pointers and comments to
my approach are highly appreciated.

kind regards,
Torsten
Reply all
Reply to author
Forward
0 new messages