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