Nope, switch statement requires compile time constants . The statement message. Contains(“test”) can evaluate true or false depending on the message so it is not a constant thus cannot be used as a ‘case’ for switch statement.
Read moreHow do you use strings on a switch case?
String in Switch Statement Example 1
Read moreCan we use string in switch case in JavaScript?
JavaScript has both. In a switch statement, the comparison with the cases is via === , and a string instance is not === to a string primitive . …that will turn it back into a primitive, whereupon your switch works.
Read more