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
Convert complex XML with element attributes to JSON
After first trying this. And getting to the point with attributes where the solution did not work
XML to Json stack overflow
I stumbled upon this url. This solution worked out of the box.