mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-09 01:01:04 -04:00
fix: use optional chaining to avoid errors (#57759)
This commit is contained in:
@@ -111,7 +111,7 @@ cashInput.dispatchEvent(new Event('change'));
|
||||
purchaseBtn.click();
|
||||
assert.strictEqual(
|
||||
alertMessage
|
||||
.trim()
|
||||
?.trim()
|
||||
.replace(/[.,?!]+$/g, '')
|
||||
.toLowerCase(),
|
||||
'customer does not have enough money to purchase the item'
|
||||
@@ -148,7 +148,7 @@ cashInput.dispatchEvent(new Event('change'));
|
||||
purchaseBtn.click();
|
||||
assert.strictEqual(
|
||||
alertMessage
|
||||
.trim()
|
||||
?.trim()
|
||||
.replace(/[.,?!]+$/g, '')
|
||||
.toLowerCase(),
|
||||
'customer does not have enough money to purchase the item'
|
||||
|
||||
@@ -70,7 +70,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store
|
||||
inputEl.value = '';
|
||||
inputEl.dispatchEvent(new Event('change'))
|
||||
checkBtn.click();
|
||||
assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value');
|
||||
assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value');
|
||||
```
|
||||
|
||||
When the `#text-input` element only contains the letter `A` and the `#check-btn` element is clicked, the `#result` element should contain the text `"A is a palindrome"`.
|
||||
|
||||
@@ -153,7 +153,7 @@ async () => {
|
||||
if (!res.ok) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000)); // Additional delay to allow the alert to trigger
|
||||
|
||||
assert.include(['pokémon not found', 'pokemon not found'], alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase());
|
||||
assert.include(['pokémon not found', 'pokemon not found'], alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase());
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
@@ -375,7 +375,7 @@ async () => {
|
||||
if (!res.ok) {
|
||||
await new Promise(resolve => setTimeout(resolve, 2000)); // Additional delay to allow the alert to trigger
|
||||
|
||||
assert.include(['pokémon not found', 'pokemon not found'], alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase());
|
||||
assert.include(['pokémon not found', 'pokemon not found'], alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase());
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
|
||||
@@ -103,7 +103,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store
|
||||
|
||||
userInput.value = '';
|
||||
checkBtn.click();
|
||||
assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a phone number');
|
||||
assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a phone number');
|
||||
```
|
||||
|
||||
When you click on the `#clear-btn` element, the content within the `#results-div` element should be removed.
|
||||
|
||||
@@ -31,7 +31,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store
|
||||
numberInput.value = '';
|
||||
checkUserInput();
|
||||
|
||||
assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0');
|
||||
assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -68,7 +68,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store
|
||||
inputEl.value = '';
|
||||
inputEl.dispatchEvent(new Event('change'))
|
||||
checkBtn.click();
|
||||
assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value');
|
||||
assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please input a value');
|
||||
```
|
||||
|
||||
When the `#text-input` element only contains the letter `A` and the `#check-btn` element is clicked, the `#result` element should contain the text `"A is a palindrome"`.
|
||||
|
||||
@@ -31,7 +31,7 @@ window.alert = (message) => alertMessage = message; // Override alert and store
|
||||
numberInput.value = '';
|
||||
checkUserInput();
|
||||
|
||||
assert.strictEqual(alertMessage.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0');
|
||||
assert.strictEqual(alertMessage?.trim().replace(/[.,?!]+$/g, '').toLowerCase(), 'please provide a decimal number greater than or equal to 0');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
Reference in New Issue
Block a user