diff --git a/lib/checks/label/duplicate-img-label.js b/lib/checks/label/duplicate-img-label.js index 7e1062553e..d184c572c2 100644 --- a/lib/checks/label/duplicate-img-label.js +++ b/lib/checks/label/duplicate-img-label.js @@ -1,5 +1,5 @@ var imgs = node.querySelectorAll('img'); -var text = axe.commons.text.visible(node, true).toLowerCase(); +var text = axe.commons.text.visible(virtualNode, true).toLowerCase(); if (text === '') { return false; diff --git a/test/checks/label/duplicate-img-label.js b/test/checks/label/duplicate-img-label.js index 9ef3b50d4d..737bdc0122 100644 --- a/test/checks/label/duplicate-img-label.js +++ b/test/checks/label/duplicate-img-label.js @@ -5,53 +5,63 @@ describe('duplicate-img-label', function () { afterEach(function () { fixture.innerHTML = ''; + axe._tree = undefined; }); it('should return false if no img is present', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isFalse(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); it('should return false if no text is present', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isFalse(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + var result = checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node)); + assert.isFalse(result); }); it('should return false if aria-label duplicates img alt', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isFalse(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); it('should return false if img and text have different text', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isFalse(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); it('should return true if img and text have the same text', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isTrue(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isTrue(checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); it('should return true if img has ARIA label with the same text', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isTrue(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isTrue(checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); it('should return false if img and text are both blank', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isFalse(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); it('should return false if img and text have superset/subset text', function () { fixture.innerHTML = ''; var node = fixture.querySelector('#target'); - assert.isFalse(checks['duplicate-img-label'].evaluate(node)); + var tree = axe._tree = axe.utils.getFlattenedTree(fixture); + assert.isFalse(checks['duplicate-img-label'].evaluate(node, undefined, axe.utils.getNodeFromTree(tree[0], node))); }); });