diff --git a/src/reactA11yAnchorsRule.ts b/src/reactA11yAnchorsRule.ts
index 91bd5e762..5b861dea3 100644
--- a/src/reactA11yAnchorsRule.ts
+++ b/src/reactA11yAnchorsRule.ts
@@ -58,7 +58,8 @@ class ReactA11yAnchorsRuleWalker extends ErrorTolerantWalker {
while (this.anchorInfoList.length > 0) {
const current: AnchorInfo = this.anchorInfoList.shift();
this.anchorInfoList.forEach((anchorInfo: AnchorInfo): void => {
- if (current.href === anchorInfo.href &&
+ if (current.href &&
+ current.href === anchorInfo.href &&
current.text !== anchorInfo.text &&
!Utils.contains(sameHrefDifferentTexts, anchorInfo)) {
diff --git a/tests/ReactA11yAnchorsRuleTests.ts b/tests/ReactA11yAnchorsRuleTests.ts
index ca2f21154..69935bfac 100644
--- a/tests/ReactA11yAnchorsRuleTests.ts
+++ b/tests/ReactA11yAnchorsRuleTests.ts
@@ -84,7 +84,7 @@ describe('reactA11yAnchorsRule', () : void => {
]);
});
- describe('Link text should be at least 4 characters long', () => {
+ describe('Link text should be at least 4 characters long', (): void => {
it('should pass when length of text equals or larger than 4', () => {
const script: string = `
import React = require('react');
@@ -96,7 +96,7 @@ describe('reactA11yAnchorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, []);
});
- it('should fail when length of text less than 4', () => {
+ it('should fail when length of text less than 4', (): void => {
const script: string = `
import React = require('react');
const anchor1 = ok;
@@ -132,6 +132,18 @@ describe('reactA11yAnchorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [ ]);
});
+ it('shoud pass when hrefs undefiend and texts are variant', (): void => {
+ const script : string = `
+ import React = require('react');
+ const anchor1 = someTitle1;
+ const anchor2 = someTitle2;
+ const anchor3 = someTitle3;
+ const anchor4 = someTitle4;
+ `;
+
+ TestHelper.assertViolations(ruleName, script, [ ]);
+ });
+
it('should pass when hrefs and texts both are different', () : void => {
const script : string = `
import React = require('react');