scommons.react.test.util.ShallowRendererUtils.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scommons-react-test_sjs0.6_2.13 Show documentation
Show all versions of scommons-react-test_sjs0.6_2.13 Show documentation
Core Scala.js, React.js testing utilities
The newest version!
package scommons.react.test.util
import io.github.shogowada.scalajs.reactjs.elements.ReactElement
import org.scalactic.source.Position
import org.scalatest.Assertion
import scommons.react.UiComponent
import scommons.react.test.raw.{ShallowInstance, ShallowRenderer}
import scommons.react.test.util.RendererUtils.{shallowInstanceUtils => utils}
@deprecated("Will be removed soon, use TestRendererUtils instead", "0.5.1")
trait ShallowRendererUtils {
def createRenderer(): ShallowRenderer = new ShallowRenderer
def shallowRender(element: ReactElement): ShallowInstance = {
val renderer = createRenderer()
renderer.render(element)
renderer.getRenderOutput()
}
def findComponentProps[T](renderedComp: ShallowInstance,
searchComp: UiComponent[T])(implicit pos: Position): T = {
utils.findComponentProps(renderedComp, searchComp)
}
def findProps[T](renderedComp: ShallowInstance, searchComp: UiComponent[T]): List[T] = {
utils.findProps(renderedComp, searchComp)
}
def findComponents(component: ShallowInstance, componentType: Any): List[ShallowInstance] = {
utils.findComponents(component, componentType)
}
def assertComponent[T](result: ShallowInstance, expectedComp: UiComponent[T])
(assertProps: T => Assertion,
assertChildren: List[ShallowInstance] => Assertion = utils.expectNoChildren
)(implicit pos: Position): Assertion = {
utils.assertComponent(result, expectedComp)(assertProps, assertChildren)
}
def assertNativeComponent(result: ShallowInstance,
expectedElement: ReactElement
)(implicit pos: Position): Assertion = {
assertNativeComponent(result, expectedElement, utils.expectNoChildren)
}
def assertNativeComponent(result: ShallowInstance,
expectedElement: ReactElement,
assertChildren: List[ShallowInstance] => Assertion
)(implicit pos: Position): Assertion = {
utils.assertNativeComponent(result, expectedElement, assertChildren)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy