Browse Source

[web] [tests] introduce elementBuilderShouldBeCalledOnce test

pull/1118/head
Shagen Ogandzhanian 3 years ago
parent
commit
d4804fafdd
  1. 28
      web/core/src/jsTest/kotlin/elements/ElementsTests.kt

28
web/core/src/jsTest/kotlin/elements/ElementsTests.kt

@ -6,6 +6,8 @@
package org.jetbrains.compose.web.core.tests.elements
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import kotlinx.browser.document
import org.jetbrains.compose.web.ExperimentalComposeWebApi
import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.testutils.*
@ -131,4 +133,30 @@ class ElementsTests {
assertEquals("<div><custom id=\"container\">CUSTOM</custom></div>", root.outerHTML)
}
@Test
fun elementBuilderShouldBeCalledOnce() = runTest {
var counter = 0
var flag = false
composition {
TagElement({
counter++
document.createElement("div")
}, null,
if (flag) {
{ Div() { Text("ON") } }
} else null
)
}
assertEquals(1, counter, )
flag = true
waitForRecompositionComplete()
assertEquals(1, counter)
assertEquals("<div><div>ON</div></div>", nextChild().outerHTML)
}
}

Loading…
Cancel
Save