Unit tests: fix tests that check className of elements

Makes sure the element has a `className` attribute before attempting `indexOf` call.

Fixes problem in #4483.