Skip to content

Commit

Permalink
Improved TestRenderer children handling
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Aug 18, 2021
1 parent 71b18bb commit 69f04b1
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/src/main/scala/scommons/react/test/util/RendererUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,26 @@ sealed trait RendererUtils[Instance <: RenderedInstance] extends Matchers {
}

private def getComponentChildren(result: Instance): List[Instance] = {
val resultChildren = result.asInstanceOf[js.Dynamic].children
val resChildren = result.asInstanceOf[js.Dynamic].children
.asInstanceOf[js.UndefOr[scalajs.js.Array[Instance]]]

// in case of ShallowInstance or ReactElement get children from props
// in case of TestInstance return children as it is
//
if (scalajs.js.isUndefined(resultChildren)) {
if (scalajs.js.isUndefined(result.props)) Nil
else {
val children = result.props.children

if (scalajs.js.isUndefined(children)) Nil
else if (scalajs.js.Array.isArray(children)) {
children.asInstanceOf[scalajs.js.Array[Instance]].toList
resChildren.toOption match {
case Some(children) if children.length > 0 => children.toList
case _ =>
if (scalajs.js.isUndefined(result.props)) Nil
else {
val children = result.props.children

if (scalajs.js.isUndefined(children)) Nil
else if (scalajs.js.Array.isArray(children)) {
children.asInstanceOf[scalajs.js.Array[Instance]].toList
}
else List(children.asInstanceOf[Instance])
}
else List(children.asInstanceOf[Instance])
}
}
else resultChildren.asInstanceOf[js.Array[Instance]].toList
}
}

Expand Down

0 comments on commit 69f04b1

Please sign in to comment.