Angular unit test directive error "Argument 'fn' is not a function, got Object"
This is my code:
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);
}
};
}]);
This is my directive unit 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);
});
});
Aucun commentaire:
Enregistrer un commentaire