All Downloads are FREE. Search and download functionalities are using the official Maven repository.

japgolly.scalajs.react.test.TestReactRoot.scala Maven / Gradle / Ivy

There is a newer version: 3.0.0-beta8
Show newest version
package japgolly.scalajs.react.test

import japgolly.scalajs.react.{facade => mainFacade, _}
import org.scalajs.dom

object TestReactRoot {

  def apply(container: mainFacade.ReactDOMClient.RootContainer): TestReactRoot =
    apply(ReactDOMClient.createRoot(container), container)

  def apply(root: ReactRoot, container: mainFacade.ReactDOM.Container): TestReactRoot = {
    @inline def r = root
    @inline def c = container
    new TestReactRoot {
      override type Self = TestDomWithRoot
      override protected def Self(n2: dom.Node) = TestDomWithRoot(this, n2)
      override def root = r

      override def container = c
      override def toString = s"TestReactRoot($root, $container)"
    }
  }
}

// =====================================================================================================================

/** Wraps a React Root (introduced in React 18) and provides utilities for testing its state.
  *
  * As an example `testRoot.innerHTML.assert("
Welcome
")` * * @since 2.2.0 / React 18 */ trait TestReactRoot extends TestContainer { override type Self <: TestDomWithRoot def root: ReactRoot @inline def raw = root.raw def render[A](unmounted: A)(implicit r: Renderable[A]): Unit = ReactTestUtils2.act(root.render(unmounted)) def unmount(): Unit = ReactTestUtils2.act(root.unmount()) }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy