Hello. I made a new project using Kotlin Multiplatform. I am trying to write a unit test in JS from the “Hello from Ktor” example. The goal is to assert I have the right class by asserting the “root” div exists. When I getElementById as HTMLDivElement or HTMLElement, I get an illegal cast error. When I don’t cast anything, I get null for those elements. I tried document and window.document. What am I doing wrong? Thank you in advance for any help.
import react.dom.render
import kotlinx.browser.document
import kotlinx.browser.window
import kotlinx.html.HTML
import kotlinx.html.id
import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement
import react.isValidElement
import kotlin.test.*
class clientTests {
// am I loading the right class?
@Test
fun checkRightClassIsLoaded() {
var element = document.getElementById("root")
if (element != null) {
println(element.id)
} else {
println("*****************why")
}
// assertEquals(2, 1+1)
}
}