From 63ca3881e8352fba3b71f2f76dae23a0d70a271f Mon Sep 17 00:00:00 2001
From: Steven Lambert <2433219+straker@users.noreply.github.com>
Date: Thu, 9 Jul 2020 08:54:38 -0600
Subject: [PATCH] fix(input-button-name): work with virtual nodes (#2352)
---
.../shared/non-empty-if-present-evaluate.js | 10 ++---
test/checks/shared/non-empty-if-present.js | 41 +++++++------------
2 files changed, 20 insertions(+), 31 deletions(-)
diff --git a/lib/checks/shared/non-empty-if-present-evaluate.js b/lib/checks/shared/non-empty-if-present-evaluate.js
index 03d0618d68..064ff335e9 100644
--- a/lib/checks/shared/non-empty-if-present-evaluate.js
+++ b/lib/checks/shared/non-empty-if-present-evaluate.js
@@ -1,8 +1,8 @@
-function nonEmptyIfPresentEvaluate(node) {
+function nonEmptyIfPresentEvaluate(node, options, virtualNode) {
// Check for 'default' names, which are given to reset and submit buttons
- let nodeName = node.nodeName.toUpperCase();
- let type = (node.getAttribute('type') || '').toLowerCase();
- let label = node.getAttribute('value');
+ let nodeName = virtualNode.props.nodeName;
+ let type = (virtualNode.attr('type') || '').toLowerCase();
+ let label = virtualNode.attr('value');
if (label) {
this.data({
@@ -10,7 +10,7 @@ function nonEmptyIfPresentEvaluate(node) {
});
}
- if (nodeName === 'INPUT' && ['submit', 'reset'].includes(type)) {
+ if (nodeName === 'input' && ['submit', 'reset'].includes(type)) {
return label === null;
}
return false;
diff --git a/test/checks/shared/non-empty-if-present.js b/test/checks/shared/non-empty-if-present.js
index e7c97c6f87..5c24300a4c 100644
--- a/test/checks/shared/non-empty-if-present.js
+++ b/test/checks/shared/non-empty-if-present.js
@@ -9,6 +9,7 @@ describe('non-empty-if-present', function() {
var isEdgeOrIe = typeof input.getAttribute('value') === 'string';
var checkContext = axe.testUtils.MockCheckContext();
+ var queryFixture = axe.testUtils.queryFixture;
afterEach(function() {
fixture.innerHTML = '';
@@ -16,15 +17,14 @@ describe('non-empty-if-present', function() {
});
it('should return false if a value is present', function() {
- var node = document.createElement('input');
- node.setAttribute('type', 'submit');
- node.setAttribute('value', 'woohoo');
- fixture.appendChild(node);
+ var vNode = queryFixture(
+ ''
+ );
assert.isFalse(
axe.testUtils
.getCheckEvaluate('non-empty-if-present')
- .call(checkContext, node)
+ .call(checkContext, null, {}, vNode)
);
assert.equal(checkContext._data.messageKey, 'has-label');
});
@@ -32,58 +32,47 @@ describe('non-empty-if-present', function() {
(isEdgeOrIe ? xit : it)(
'should return true if a value is not present',
function() {
- var node = document.createElement('input');
- node.setAttribute('type', 'submit');
- fixture.appendChild(node);
+ var vNode = queryFixture('');
assert.isTrue(
axe.testUtils
.getCheckEvaluate('non-empty-if-present')
- .call(checkContext, node)
+ .call(checkContext, null, {}, vNode)
);
assert.isNull(checkContext._data);
}
);
it('should return false if an value is present, but empty', function() {
- var node = document.createElement('input');
- node.setAttribute('type', 'submit');
- node.setAttribute('value', '');
- fixture.appendChild(node);
+ var vNode = queryFixture('');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('non-empty-if-present')
- .call(checkContext, node)
+ .call(checkContext, null, {}, vNode)
);
});
it('should return false if the element is not a submit or reset input', function() {
- var node = document.createElement('input');
- node.setAttribute('type', 'text');
- fixture.appendChild(node);
+ var vNode = queryFixture('');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('non-empty-if-present')
- .call(checkContext, node)
+ .call(checkContext, null, {}, vNode)
);
- node = document.createElement('input');
- node.setAttribute('type', 'button');
- fixture.appendChild(node);
+ var vNode = queryFixture('');
assert.isFalse(
axe.testUtils
.getCheckEvaluate('non-empty-if-present')
- .call(checkContext, node)
+ .call(checkContext, null, {}, vNode)
);
- node = document.createElement('button');
- node.setAttribute('type', 'submit');
- fixture.appendChild(node);
+ var vNode = queryFixture('