initDriver <- function(app) { shinytest2::AppDriver$new(app, variant = shinytest2::platform_variant()) } describe("rendering with htmltools::HTML", { it("renders HTML strings in React context from ui function when wrapped with `htmltools::HTML`", { skip_on_cran() # Arrange app <- initDriver(shiny::shinyApp( ui = ReactContext(htmltools::HTML( 'Hello World' )), server = function(input, output) {} )) withr::defer(app$stop()) # Act html <- app$get_html("#test") # Assert expect_equal( html, 'Hello World' ) }) it("renders HTML strings from renderReact when wrapped with `htmltools::HTML`", { skip_on_cran() # Arrange app <- initDriver(shiny::shinyApp( ui = reactOutput("react_output"), server = function(input, output) { output$react_output <- renderReact({ htmltools::HTML( 'Hello World' ) }) } )) withr::defer(app$stop()) # Act html <- app$get_html("#test") # Assert expect_equal( html, 'Hello World' ) }) it("doesn't render HTML strings in React context without `htmltools::HTML`", { set.seed(1) skip_on_cran() # Arrange app <- initDriver(shiny::shinyApp( ui = ReactContext( 'Hello World' ), server = function(input, output) {} )) withr::defer(app$stop()) # Act html <- app$get_html("#test") htmlContainer <- app$get_html(".react-container") # Assert # Span hasn't been rendered as HTML, so it's null expect_null(html) # The container div has been rendered as HTML, but the span is escaped expect_equal( htmlContainer, '