-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(link-in-text-block): don't match style or script text (#3775)
* fix(link-in-text-block): don't match style or script text * fake img
- Loading branch information
Showing
5 changed files
with
120 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,82 @@ | ||
describe('link-in-text-block-matches', function () { | ||
describe('link-in-text-block-matches', () => { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var fixtureSetup = axe.testUtils.fixtureSetup; | ||
var rule; | ||
const { fixtureSetup } = axe.testUtils; | ||
const rule = axe.utils.getRule('link-in-text-block'); | ||
|
||
beforeEach(function () { | ||
rule = axe.utils.getRule('link-in-text-block'); | ||
}); | ||
|
||
afterEach(function () { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should return true if link is in text block', function () { | ||
it('should return true if link is in text block', () => { | ||
fixtureSetup( | ||
'<p>Some paragraph with text <a id="target" href="#">world</a></p>' | ||
); | ||
var node = document.getElementById('target'); | ||
const node = document.getElementById('target'); | ||
assert.isTrue(rule.matches(node)); | ||
}); | ||
|
||
it('should return false if element has a non-link role', function () { | ||
it('should return false if element has a non-link role', () => { | ||
fixtureSetup( | ||
'<p>Some paragraph with text <a id="target" href="#" role="button">hello</a></p>' | ||
); | ||
var node = document.getElementById('target'); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
|
||
it('should should return false if element does not have text', function () { | ||
it('should should return false if element does not have text', () => { | ||
fixtureSetup( | ||
'<p>Some paragraph with text <a id="target" href="#"></a></p>' | ||
); | ||
var node = document.getElementById('target'); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
|
||
it('should return false if element has <style>', () => { | ||
fixtureSetup(` | ||
<p>Some paragraph with text | ||
<a id="target" href="#"> | ||
<style>a { color: #333 }</style> | ||
</a> | ||
</p> | ||
`); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
|
||
it('should return false if element has <script>', () => { | ||
fixtureSetup(` | ||
<p>Some paragraph with text | ||
<a id="target" href="#"> | ||
<script>console.log('foo')</script> | ||
</a> | ||
</p> | ||
`); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
|
||
it('should return false if element is hidden', function () { | ||
it('should return false if element is hidden', () => { | ||
fixtureSetup( | ||
'<p>Some paragraph with text <a id="target" href="#"" style="display: none">hello</a></p>' | ||
); | ||
var node = document.getElementById('target'); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
|
||
it('should return false if link is not in text block', function () { | ||
it('should return false if link is not in text block', () => { | ||
fixtureSetup('<a id="target" href="#">hello</a>'); | ||
var node = document.getElementById('target'); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
|
||
it('should return false if link is only text in block', function () { | ||
it('should return false if link is only text in block', () => { | ||
fixtureSetup('<p><a id="target" href="#">world</a></p>'); | ||
var node = document.getElementById('target'); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
|
||
it('should return false if link is display block', function () { | ||
it('should return false if link is display block', () => { | ||
fixtureSetup( | ||
'<p>Some paragraph with text <a id="target" href="#" style="display: block">world</a></p>' | ||
); | ||
var node = document.getElementById('target'); | ||
const node = document.getElementById('target'); | ||
assert.isFalse(rule.matches(node)); | ||
}); | ||
}); |