import kotlinx.html.consumers.catch import kotlinx.html.dom.append import kotlinx.html.h1 import kotlinx.html.h2 import kotlinx.html.js.div import org.junit.Test import kotlin.browser.document import kotlin.test.assertEquals class TestExceptions { @Test fun `exception_handler_should_add_output`() { val container = document.body!!.append.catch { err -> div { +"ERROR: " +err.message!! } }.div { h1 { +" text " throw IllegalStateException("testing errors") } h2 { +" should be present " } } assertEquals( """

text
ERROR: testing errors

should be present

""", container.innerHTML.trimTagSpace()) } fun String.trimTagSpace() = replace(">\\s+<".toRegex(), "><") }