fix: use optional chaining to avoid errors (#57759)

This commit is contained in:
Ilenia
2025-01-02 10:31:26 +01:00
committed by GitHub
parent ade0aa8052
commit e3eccef3fb
7 changed files with 9 additions and 9 deletions

View File

@@ -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'

View File

@@ -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"`.

View File

@@ -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);

View File

@@ -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.

View File

@@ -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--

View File

@@ -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"`.

View File

@@ -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--