I have an array containing various substrings, and I want to pass if at least one of those substrings contains the specific value I am searching for.
Value1 = [
"Grape | 100 |Food Catering Service",
"Apple | 100,000m |Food Catering Service",
"Water Melon | 100,000m |Catering Service Outside",
"100,000m |Food Catering Service Outside
]
Using TypeScript, my goal is to ensure that if any substring in the array contains the word "Food," it should pass. Even if some substrings do not contain the word "Food," the overall test should still pass.
The code snippet below is what I have tried so far, but it does not achieve the desired outcome, as it simply returns the array without filtering based on the search criteria.
export function arraySubstring(expected: string, ignoreCase?: boolean): Expectation<string[], string> {
return Expectation.that("test", expected, async(actor: Actor, actual: string[]): Promise<boolean> ==> {
try {
for (const value of actual) {
if(ignoreCase) {
if (!value.toLowerCase().includes(expected.toLowerCase())) return false;
} else {
if (!value.includes(expected)) return false;
}
}
return true;
})
}
const value2 = await webActor.attemptsTo(Ensure.that("my expectation",
value1, arraySubstring("Food")))