2
我想將attrs
設置爲未定義的單元測試,我嘗試了幾種方法,但未將其設置爲undefined
。下面是我的指令:如何將attrs數組設置爲未定義的指令
angular.module('myApp').directive('someElement', function() {
var directive = {};
directive.restrict = 'E';
directive.replace = true;
directive.transclude = true;
directive.templateUrl = function (element, attrs) {
var template = '';
if(attrs) { // would like to invoke this in unit test and set it to `undefined`
//do something
}
return template;
};
directive.scope = {...};
directive.compile = function() {
//do something
return directive;
});
這裏是一個片斷,假設指令編譯和$digest
週期被觸發。以下是我在測試中得到:
it('should set attrs to undefined', function() {
.....
attrs = {};
scope.$apply();
expect(attrs).toBeUndefined(); // I want this to pass!!
});
1日你會怎樣做it..then你怎麼值隔離範圍 –
實現TBH它並沒有真正不管我怎麼樣努力實現,我想問問,如果這是可能的和如何! –
你是否試圖讓它'如果(attrs)attrs = {}'? –