vendredi 31 juillet 2015

Unit testing angular with ui-router shows error related to $state

I have a very simple controller:

angular.module("myApp").controller("TestCtr", function ($scope) {
        $scope.value = 5;
        $scope.func = function () {
            return 10;
        };
    });

And I am about to start learning how to do unit tests using karma.. The problem is that myApp has module dependencies

angular.module("myApp",["ui.router", "blueimp.fileupload", "ui.bootstrap"]);

I started writing some test code ...

describe("TestCtrl", function($log) {
    "use strict";

    it("first test", function () {
        expect(1).toEqual(1);
    });

    beforeEach(angular.mock.module("myApp"));

    beforeEach(inject(function() {}));
});

Everything works fine but when I add the last line, trying to start injecting things I get this error..

e 44.0.2403 (Windows 7 0.0.0) CreateCtrl first test FAILED
        Error: [$injector:unpr] Unknown provider: htmlTemplateCacheBusterProvider <- htmlTemplateCacheBuster <- $http <- $templateFactory <- $view <- $state
        http://ift.tt/1KFD9k1
            at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:63:12
            at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:3994:19
            at Object.getService [as get] (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4141:39)
            at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:3999:45
            at Object.getService [as get] (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4141:39)
            at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:8777:23
            at forEach (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:323:20)
            at $HttpProvider.$get (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:8775:5)
            at Object.invoke (C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4182:17)
            at C:/Workspace/myApp/Dev/UI/app/lib/angular/1.3.9/angular.js:4000:37
Chrome 44.0.2403 (Windows 7 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.028 secs / 0.015 secs)

I assume it has to do with ui-router that needs to be injected in the module.

If anyone could help me I would appreciate it! I am using Angular and Mocks v 1.3.9 and ui-router 0.2.13...

Thanks

Aucun commentaire:

Enregistrer un commentaire