0
我試圖在一個限制爲屬性的Angular指令上運行幾個單元測試。現在我只是想確定指令是否存在。沒有模板的測試指令屬性
有誰知道如何測試指令,是一個屬性而已?
這裏是一個光禿禿的骨頭版本指令
function ResetCustomer() {
return {
restrict: 'A',
link: (scope, elem) => {
elem.bind('click', function() {
//do stuff
});
}
};
}
export default {
name: 'resetCustomer',
fn: ResetCustomer
};
... ...的HTML
<a class="brand" reset-customer>
<img src="path/to/image.jpg"/>
</a>
...和測試
describe('Unit: ResetCustomer',() => {
let element, scope, compile;
beforeEach(() => {
angular.mock.module('app');
angular.mock.inject(($compile, $rootScope) => {
scope = $rootScope.$new();
compile = $compile;
element = angular.element('<a reset-customer></a>');
compile(element)(scope);
scope.$digest();
});
});
it('should exist',() => {
expect(element).toBeDefined();
});
});
看這裏:http://stackoverflow.com/questions/35570189/creating-single-custom-directive - 用於-NG-點擊即可執行,多控制器樂趣/ 35570797#35570797 我寫了有一個指令,不ES6但也許它會幫助你 – CodeNashor
謝謝,但我正在尋找一種方法來測試指示。 – abyrne85