Reputation: 19453
I have an unit test that look like this:
describe("myDirective Test",function(){
beforeEach(module('app'));
beforeEach(function() {
module(function($provide) {
$provide.constant('Config', {"showmenu":true});
});
});
it('should add showmenu attribute',inject(function($compile,$rootScope){
var element = $compile('<div my-directive></div>')($rootScope);
expect(element.attr('showmenu')).not.toBe(undefined);
}));
it('should NOT add showmenu attribute',inject(function($compile,$rootScope){
var element = $compile('<div my-directive></div>')($rootScope);
expect(element.attr('showmenu')).toBe(undefined);
}));
});
This is my directive:
.directive('myDirective', ['$compile','Config', function($compile,Config){
return {
scope: true,
link: function(scope, element) {
if(Config.showmenu){
element.attr('showmenu', "{'height':menuheight,'alwaysVisible':true}");
element.removeAttr('my-directive');
$compile(element)(scope);
}
}
};
}]);
How can I change the showmenu
value, so that it is false
in the should NOT add showmenu attribute
test?
Upvotes: 0
Views: 998
Reputation: 5825
Try to inject Config to your test, and change it there:
it('should NOT add showmenu attribute',inject(function($compile,$rootScope, Config){
Config.showmenu = false;
var element = $compile('<div my-directive></div>')($rootScope);
expect(element.attr('showmenu')).toBe(undefined);
}));
Not sure if your real code is like that, but you have a extra space here:
.directive('myDirective '
Upvotes: 1