0
我有一個看起來像這樣的單元測試:變化角度模擬值
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);
}));
});
這是我的指令:
.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);
}
}
};
}]);
我怎樣才能改變showmenu
價值,所以它是false
在should NOT add showmenu attribute
測試?
你能在使用'showmenu'的地方共享指令模板? – Chandermani 2015-04-02 08:48:06
@Chandermani我用我的指令示例更新了我的問題。那麼,怎麼做呢?謝謝。 – user1995781 2015-04-02 09:06:14