title: Cordova sqliteplugin karma test description
body: <p>Hello I want to implement some test cases for my ionic framework application which uses cordova sqliteplugin to get data from a sqlite database. </p>
  
  <p>I'm very new in writing test cases for angularjs. </p>
  
  <p>My goal is to test if there is data coming for my service.</p>
  
  <p>Well in my app.js I open the database with this:</p>
  
  <pre><code>angular.module('starter', ['ionic','starter.services', 'starter.controllers', 'starter.config','ngCordova'])
  
  .run(function($ionicPlatform, $cordovaSQLite, $ionicLoading) {
    $ionicPlatform.ready(function() {
  
      var dbName = 'testDB.db';
      if(window.cordova) {
        window.plugins.sqlDB.copy(dbName);
        db = $cordovaSQLite.openDB(dbName);
      }
  
      ....
  </code></pre>
  
  <p>My services.js are looking like this:</p>
  
  <pre><code>angular.module('starter.services', ['ngCordova'])
  
  .factory('ProductService',function($cordovaSQLite){
  
      var getAllProducts = function() {
          var productList = [];
  
          var query = "SELECT c.name as name, c.id as id FROM cars as c ORDER BY c.name";
          $cordovaSQLite.execute(db, query, []).then(function(res) {
  
              if(res.rows.length &gt; 0) {
  
                  for(var i = 0; i &lt; res.rows.length; i++) {
                      productList.push({id: res.rows.item(i).id, name: res.rows.item(i).name});
                  }
  
              }
          }, function (err) {
              console.error(err);
          });
  
          return productList;
      };
  
      return {
          getAllProducts: getAllProducts
      };
  
  });
  </code></pre>
  
  <p>And my test description to test the service looks like this:</p>
  
  <pre><code>describe('ProductService unit tests', function () {
      var ProductService;
  
      beforeEach(module('starter.services'));
      beforeEach(angular.mock.module('starter'));
  
      beforeEach(inject(function(_ProductService_) {
          ProductService = _ProductService_;
      }));
  
      it('can get an instance', inject(function(ProductService) {
          expect(ProductService).toBeDefined();
      }));
  
      //THIS TEST FAILS
      it('should get some products from the database', inject(function(ProductService) {
          expect(ProductService.getAllProducts().length).toBeGreaterThan(0);
      }));
  });
  </code></pre>
  
  <p>If I run the test I get:</p>
  
  <pre><code>TypeError: 'null' is not an object (evaluating 'n.transaction')
  </code></pre>
  
  <p>I think its because the database is not really initialized during the test, so I tried to mock the starter app but it didn't solve the problem. I tried to google on this but could not find any examples or tutorials for karma with sqlite and angularjs. </p>
  
  <p>Thanks for any help.</p>