|
3 | 3 | describe('a', function() {
|
4 | 4 | var element, $compile, $rootScope;
|
5 | 5 |
|
| 6 | + beforeEach(module(function($compileProvider) { |
| 7 | + $compileProvider. |
| 8 | + directive('linkTo', valueFn({ |
| 9 | + restrict: 'A', |
| 10 | + template: '<div class="my-link"><a href="{{destination}}">{{destination}}</a></div>', |
| 11 | + replace: true, |
| 12 | + scope: { |
| 13 | + destination: '@linkTo' |
| 14 | + } |
| 15 | + })). |
| 16 | + directive('linkNot', valueFn({ |
| 17 | + restrict: 'A', |
| 18 | + template: '<div class="my-link"><a href>{{destination}}</a></div>', |
| 19 | + replace: true, |
| 20 | + scope: { |
| 21 | + destination: '@linkNot' |
| 22 | + } |
| 23 | + })); |
| 24 | + })); |
6 | 25 |
|
7 | 26 | beforeEach(inject(function(_$compile_, _$rootScope_) {
|
8 | 27 | $compile = _$compile_;
|
@@ -76,6 +95,40 @@ describe('a', function() {
|
76 | 95 | });
|
77 | 96 |
|
78 | 97 |
|
| 98 | + it('should not preventDefault if anchor element is replaced with href-containing element', function() { |
| 99 | + spyOn(jqLite.prototype, 'on').andCallThrough(); |
| 100 | + element = $compile('<a link-to="https://www.google.com">')($rootScope); |
| 101 | + $rootScope.$digest(); |
| 102 | + |
| 103 | + var child = element.children('a'); |
| 104 | + var preventDefault = jasmine.createSpy('preventDefault'); |
| 105 | + |
| 106 | + child.triggerHandler({ |
| 107 | + type: 'click', |
| 108 | + preventDefault: preventDefault |
| 109 | + }); |
| 110 | + |
| 111 | + expect(preventDefault).not.toHaveBeenCalled(); |
| 112 | + }); |
| 113 | + |
| 114 | + |
| 115 | + it('should preventDefault if anchor element is replaced with element without href attribute', function() { |
| 116 | + spyOn(jqLite.prototype, 'on').andCallThrough(); |
| 117 | + element = $compile('<a link-not="https://www.google.com">')($rootScope); |
| 118 | + $rootScope.$digest(); |
| 119 | + |
| 120 | + var child = element.children('a'); |
| 121 | + var preventDefault = jasmine.createSpy('preventDefault'); |
| 122 | + |
| 123 | + child.triggerHandler({ |
| 124 | + type: 'click', |
| 125 | + preventDefault: preventDefault |
| 126 | + }); |
| 127 | + |
| 128 | + expect(preventDefault).toHaveBeenCalled(); |
| 129 | + }); |
| 130 | + |
| 131 | + |
79 | 132 | if (isDefined(window.SVGElement)) {
|
80 | 133 | describe('SVGAElement', function() {
|
81 | 134 | it('should prevent default action to be executed when href is empty', function() {
|
|
0 commit comments