R
R
Roma Cockenshtuff2016-03-12 21:33:53
Angular
Roma Cockenshtuff, 2016-03-12 21:33:53

How to fix unit test problem?

Test code:

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(true);
        expect(mockScope.deletingSuccess).toBe(true);
        expect(mockScope.updatingSuccess).toBe(true);
    });
});

karma.config.js :
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/*.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