Hi! I would like to ask is it possible to test `@C...
# compose-desktop
n
Hi! I would like to ask is it possible to test
@Composable
function that calls WindowScope functions. Here is an example of how my test is defined:
Copy code
class Test {

    @get:Rule
    val composeRule = createComposeRule()

    @OptIn(ExperimentalMaterialApi::class)
    @Test
    fun `test main window`() {

        composeRule.setContent {
            MainWindow(
                mainScreen = { mainScreen() },
            )
        }

        runBlocking {
            println(composeRule.onRoot().printToString())
            composeRule.onNodeWithTag(MAIN_SCREEN).assertExists()
            composeRule.onNodeWithText(SOME_TEXT).assertExists()
        }
    }

}

@Composable
fun MainWindow(
    mainScreen: @Composable () -> Unit,
) {

    Window(onCloseRequest = {}) {
        MaterialTheme {
            mainScreen()
        }
    }
}

@Composable
private fun mainScreen() {
    Column(Modifier.fillMaxSize().testTag(MAIN_SCREEN)) {
        Text(SOME_TEXT)
    }
}

const val MAIN_SCREEN = "main_screen"
const val SOME_TEXT = "Some text"
The test is failing and when I print the whole view hierarchy it just shows only one node without any children
Copy code
Printing with useUnmergedTree = 'false'
Node #1 at (l=0.0, t=0.0, r=0.0, b=0.0)px
but as soon as I remove the
Window
method from
MainWindow
the test is passing and the view hierarchy is correct.
Copy code
Printing with useUnmergedTree = 'false'
Node #1 at (l=0.0, t=0.0, r=1024.0, b=768.0)px
 |-Node #2 at (l=0.0, t=0.0, r=1024.0, b=768.0)px, Tag: 'main_screen'
    |-Node #3 at (l=0.0, t=0.0, r=78.0, b=19.0)px
      Text = '[Some text]'
      Actions = [GetTextLayoutResult]
Any ideas?
🧵 2