To be able to develop in TDD
As a PhoneGap developer using Jasmine and Karma
I want to be able to run Jasmine spec files inside a PhoneGap application
So I can verify my Cordova specific code in my unit tests
Based on karma #472, it doesn't work for some/most people, but some claim it can be done.
What I'm trying to achieve is to have access to the Cordova environment (eg. FileSystem API, battery events, etc.) in my spec files/tests. (I do mock a lot of services by the way, but I'd like to access the real API)
I have tried to redirect the Cordova app to Karma runner page with window.location = 'http://karma:8080'
, and while I can load the base cordova.js
file inside the tests, deviceready
never fires (see ticket), plus I'm unable to grab the JS code that are required to have plugin functionality (ie. code depending on plugins can't be tested).
I've tried to create an <iframe>
pointing to Karma inside the Cordova app, but that also couldn't access cordova
.
I have found others are injecting cordova to window.parent
, but I don't really see how that could work (I can't access window.parent
from my <iframe>
).
I have tried to do these in ripple-emulator and in Android AVDs, with the same lack of success.
Any pointers are really appreciated. I'm using Cordova 3.4.1 on Android (not targeting iOS), and latest Karma & Jasmine, plus AngularJS 1.3.