Testing project with Karma, Unknown provider: $$rAFProvider


#1

from karma.con.js:

files: [
      'www/lib/ionic/js/angular/angular.js',
      'www/lib/ionic/js/angular/angular-animate.js',
      'www/lib/ionic/js/angular/angular-sanitize.js',
      'www/lib/ionic/js/angular-ui/angular-ui-router.js',
      'www/lib/ionic/js/ionic.bundle.js',
      'www/lib/ionic/js/ionic-angular.js',
      'tests/unit/lib/angular-mocks/angular-mocks.js',
      'www/js/**/*.js',
      'tests/**/*.js'
],

Test Code:

describe('DealCtrl', function () {
    beforeEach(module('krazy.controllers'));

    var ctrl
        , scope;

    beforeEach(inject(function ($controller) {
        scope = {};
        ctrl = $controller('DealCtrl', {$scope: scope});
    }));

    it('should do something', function(done) {
      expect(scope.dealId).toBeDefined();
    });
});

Running karma start gives me the following error:

$ karma start
INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 34.0.1847 (Mac OS X 10.9.2)]: Connected on socket jA6UYSkdnaJ-bRvoKtnS with id 23310616
Chrome 34.0.1847 (Mac OS X 10.9.2) DealCtrl should do something FAILED       
        Error: [$injector:modulerr] Failed to instantiate module ngMock due to:
        Error: [$injector:unpr] Unknown provider: $$rAFProvider
        http://errors.angularjs.org/1.2.12/$injector/unpr?p0=%24%24rAFProvider
            at /Users/d/src/samples/ionic/sample/www/lib/ionic/js/ionic.bundle.js:12754:12

I looked through GitHub and couldn’t find any sample projects that use Karma for test, are there any?


#2

hi wdbetts,

i have a similar error/ problem - did you progress ?

if so what did you do ?

there are some discussion here: https://github.com/driftyco/ionic/issues/891 - i have not yet solved it my self for unit tests (jasmine / karma) using module ngMock / $httpBackend

//

pelle


#3

well i solved i by:

  1. using the lib files of https://github.com/driftyco/ionic/tree/master/config/lib (this is angular 1.2.12 - which feels awkward because the loaded angular when starting app is 1.2.16)

  2. and with a karma config looking like:

    module.exports = function(config){
    config.set({

    basePath : ‘…/’,

    files: [
    // Include jQuery only for testing convience (lots of DOM checking for unit tests on directives)
    http://codeorigin.jquery.com/jquery-1.10.2.min.js’,
    ‘config/lib/js/angular/angular.js’,
    ‘config/lib/js/angular/angular-animate.js’,
    ‘config/lib/js/angular/angular-sanitize.js’,
    ‘config/lib/js/angular/angular-mocks.js’,
    ‘config/lib/js/angular/angular-resource.js’,
    ‘config/lib/js/angular-ui/angular-ui-router.js’,
    ‘www/lib/ionic/js/ionic.bundle.js’,
    ‘www/lib/ionic/js/ionic-angular.js’,
    ‘www/js//*.js’,
    'test/unit/
    /*.js’
    ],

    exclude: [
    ‘js/ext/angular/test/dom-trace.js’
    ],

    frameworks: [‘jasmine’],
    reporters: [‘progress’],
    port: 9876,
    colors: true,
    // possible values: ‘OFF’, ‘ERROR’, ‘WARN’, ‘INFO’, 'DEBUG’
    logLevel: ‘INFO’,
    autoWatch: true,
    captureTimeout: 60000,
    singleRun: false,

    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera (has to be installed with npm install karma-opera-launcher)
    // - Safari (only Mac; has to be installed with npm install karma-safari-launcher)
    // - PhantomJS
    // - IE (only Windows; has to be installed with npm install karma-ie-launcher)
    browsers: [‘Chrome’]

    });
    };


#4

Thanks! this post helped me to solve the issue.
But I included the ionic.js instead of ionic-angular.js