Do you have similar objections about untyped strings when setting the "class" attribute? The class attribute also "does things", like change layout, text styling and even behaviour in CSS animations.
How do you unit test any dynamic behaviour on HTML pages? There are multiple ways depending on what you want to check.