I'm trying to run a few unit tests on an Angular directive which is restricted to an Attribute. For now I'm only trying to ascertain that the directive exists.
Does anyone know how to test a directive that is an attribute only?
Here is a bare bones version of the directive
function ResetCustomer() {
return {
restrict: 'A',
link: (scope, elem) => {
elem.bind('click', function() {
//do stuff
});
}
};
}
export default {
name: 'resetCustomer',
fn: ResetCustomer
};
... the HTML
<a class="brand" reset-customer>
<img src="path/to/image.jpg"/>
</a>
...and the test
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();
});
});
Aucun commentaire:
Enregistrer un commentaire