mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix: allow implicit labels in checkout lab tests (#63789)
This commit is contained in:
@@ -113,7 +113,11 @@ All of your `input` elements that aren't a `type` of `submit` should have a `lab
|
||||
```js
|
||||
const inputs = document.querySelectorAll('input:not([type="submit"])');
|
||||
assert.isAtLeast(inputs.length, 1);
|
||||
inputs.forEach(input => assert.exists(document.querySelector(`label[for="${input.id}"]`)));
|
||||
inputs.forEach(input => {
|
||||
const label = document.querySelector(`label[for="${input.id}"]`) || input.parentElement;
|
||||
assert.exists(label);
|
||||
assert.equal(label.tagName, "LABEL");
|
||||
});
|
||||
```
|
||||
|
||||
You should have at least two `input` elements with the `required` attribute.
|
||||
@@ -133,7 +137,9 @@ const requiredInputs = Array.from(document.querySelectorAll('input'))
|
||||
assert.isNotEmpty(requiredInputs);
|
||||
|
||||
requiredInputs.forEach(input => {
|
||||
const label = document.querySelector(`label[for="${input.id}"]`);
|
||||
const label = document.querySelector(`label[for="${input.id}"]`) || input.parentElement;
|
||||
assert.exists(label);
|
||||
assert.equal(label.tagName, "LABEL");
|
||||
const span = label?.querySelector('span');
|
||||
assert.equal(span?.textContent.trim(), '*');
|
||||
});
|
||||
@@ -148,7 +154,9 @@ const requiredInputs = Array.from(document.querySelectorAll('input'))
|
||||
assert.isNotEmpty(requiredInputs);
|
||||
|
||||
requiredInputs.forEach(input => {
|
||||
const label = document.querySelector(`label[for="${input.id}"]`);
|
||||
const label = document.querySelector(`label[for="${input.id}"]`) || input.parentElement;
|
||||
assert.exists(label);
|
||||
assert.equal(label.tagName, "LABEL");
|
||||
const span = label?.querySelector('span');
|
||||
assert.equal(span?.getAttribute('aria-hidden'), 'true');
|
||||
});
|
||||
@@ -161,7 +169,10 @@ const cardNumberInput = document.getElementById('card-number');
|
||||
const cardNumberHelp = document.getElementById('card-number-help');
|
||||
|
||||
assert.exists(cardNumberHelp);
|
||||
assert.equal(cardNumberInput.nextElementSibling, cardNumberHelp);
|
||||
const nextElement = cardNumberInput.parentElement?.tagName === 'LABEL'
|
||||
? cardNumberInput.parentElement.nextElementSibling
|
||||
: cardNumberInput.nextElementSibling;
|
||||
assert.equal(nextElement, cardNumberHelp);
|
||||
```
|
||||
|
||||
Your card number help text should not be empty.
|
||||
|
||||
Reference in New Issue
Block a user