How can I unit test use a function inside a directory link? I tried something like this but didn't work:
directive:
app.directive("hello", function(){
return {
link: function(scope){
scope.hello = function(){
return "hello";
};
}
};
});
unit test:
describe("Hello directive", function(){
var compile, scope;
beforeEach(inject(function($compile, $rootScope){
scope = $rootScope.$new();
compile = $compile;
}));
it("should return hello", function(){
var element = compile("<hello></hello>")(scope);
expect(element.scope.hello()).toBe("hello");
});
});
Csati source
share