Ошибка директивы углового модульного теста «Аргумент« fn »не является функцией, получил объект»

0

Угловая ошибка проверки единицы измерения "Аргумент 'fn' не является функцией, получен объект"

Это мой код:

angular.module("myApp.directives")
    .directive("menu", ["$rootScope", function ($rootScope) {
        return {
            restrict: "E",
            template: "<div class=\"tabs col-xs-12\" ng-transclude />",
            transclude: true,
            link: function (scope, elem, attrs) {

                scope.test= function () {
                };    

                $rootScope.$on("$viewContentLoaded", scope.test);

            }
        };
    }]);

Это мой контрольный модуль:

describe("menu component:", function () {
    var element,
        scope,
        rootScope,
        mockValue1 = "mock",
        mockTabs = [
            "<menu name=\"" + mockValue1 + "\"><span>" + mockValue1 + "</span></menu>"
        ];

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

    beforeEach(inject(function($rootScope, $compile) {
        rootScope = $rootScope;
        scope = $rootScope.$new();

        element = $compile(mockTabs[0])(scope);
        angular.element(document.body).append(element);

        sinon.stub(rootScope, "$on");

        scope.$digest();
    }));

    it("should have called viewContentLoaded on setup", function () {
        expect(rootScope.$on.calledWith("$viewContentLoaded", scope.test)).toEqual(true);
    });   
});
Теги:
unit-testing
jasmine

1 ответ

0

использование

beforeEach(module('myApp.directives'));

вместо

beforeEach(angular.mock.module("myApp.directives"));
  • 0
    Это не исправит это.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню