From b47ece72c8e4b4748f42d9390b99c755650cb712 Mon Sep 17 00:00:00 2001 From: dimssu <146713101+dimssu@users.noreply.github.com> Date: Fri, 12 Dec 2025 14:46:27 +0530 Subject: [PATCH] fix: allow implicit labels in checkout lab tests (#63789) --- .../66da326c02141df538f29ba5.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/curriculum/challenges/english/blocks/lab-checkout-page/66da326c02141df538f29ba5.md b/curriculum/challenges/english/blocks/lab-checkout-page/66da326c02141df538f29ba5.md index df86d28732d..69ff77e4bf1 100644 --- a/curriculum/challenges/english/blocks/lab-checkout-page/66da326c02141df538f29ba5.md +++ b/curriculum/challenges/english/blocks/lab-checkout-page/66da326c02141df538f29ba5.md @@ -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.