R
R
Roma Cockenshtuff2016-03-13 11:06:36
Angular
Roma Cockenshtuff, 2016-03-13 11:06:36

Unit test problem in karma, how to solve?

test:

describe("root controller tests", function () {

    var mockScope = {};
    var controller;
    beforeEach(angular.mock.module('blogApp'));

    beforeEach(angular.mock.inject(function ($controller, $rootScope) {

        mockScope = $rootScope.$new();

        controller = $controller('rootController', {
            $scope: mockScope
        });

    }));

    it("init variables", function () {
        expect(mockScope.loading).toBe(true);
        expect(mockScope.creatingSuccess).toBe(false);
        expect(mockScope.deletingSuccess).toBe(false);
        expect(mockScope.updatingSuccess).toBe(false);
    });
    it('execute functions', function () {
        mockScope.hideNotifications();
        expect(mockScope.creatingSuccess).toBe(false);
        expect(mockScope.deletingSuccess).toBe(false);
        expect(mockScope.updatingSuccess).toBe(false);
    });
});

karma config:
files: [
      'public/js/angular.js',
      'public/js/angular-mocks.js',
      'public/js/blogApp/blogApp.js',
      'public/js/blogApp/blogServices.js',
      'public/js/blogApp/blogControllers.js',
      'public/js/blogApp/blogDirectives.js',
      'public/js/blogApp/blogFilters.js',
      'public/js/tests/blogTests/rootControllerTest.js'
    ],

the problem is that the test does not see my module and controller, this is what is output in the console:
https://docs.angularjs.org/error/$injector/moduler...
Expected undefined to be true.
TypeError: mockScope.hideNotifications is not a function

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question