Better way to wait for the timeout of events. Angularjs mocks has special methods to flush() so you do not have to wait for an event to occur.
Update(22/04) Better to use this http://jsfiddle.net/onekilo79/KS6MY/
What I have learned from testing using Jasmine 1.3 and waiting for event test using a directive.
Learned the hard way on how to mock a service that we also use jasmine to spy upon. The service returns the http promise which the controller deals with by adding things on the scope.
I was writing a unit test for my angularjs app and I ran into the following problem.
I was setting up the test correctly to inject in the $httpBackend to mock out the http calls, but the when I called called the service and then called $httpBackend.flush() it would return an error:
httpBackend no pending request to flush
Which is not what I was expecting.
When I commented out the $httpBackend.whenGET
The following 2 methods in the afterEach function would not throw an error either.
This would pass the test even though the expectations were never triggered.
Here is an example of the code I was testing with.
I ran into this problem with Testem not picking up phantomjs from the command line to run the tests.
npm folder where the installs occur for globals was still owned by root.
If I tried to run phantomjs from the command line it would throw up a stack trace about ownership.
The solution Chown
sudo chown -R the location where the global node modules are installed by npm.
sudo chown -R YOURUSER:YOURGROUP /usr/local/lib/node_modules/
sudo chown -R YOURUSER:YOURGROUP /usr/lib/node_modules/
Do not put phantomjs in your package.json of your node project.
When you call npm install it will install the package locally in your project’s node_modules folder.
When you try and run grunt test you will get an error message similar to this.
phantomjs cannot be started.
Fixing local phantomjs install
Phantomjs must be installed globally.
npm install -g phantomjs
After first trying this. And getting to the point with attributes where the solution did not work
I stumbled upon this url. This solution worked out of the box.