Skip to content

Commit d4ad8ae

Browse files
committed
Make ReactTestUtils.{replace,modify}Props work with any kind of component
1 parent 201765b commit d4ad8ae

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

test/src/main/scala/japgolly/scalajs/react/test/ReactTestUtils.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,16 @@ object ReactTestUtils {
189189

190190
// ===================================================================================================================
191191

192-
def modifyProps[P, S, B](c: ScalaComponent[P, S, B, CtorType.Props])(m: ScalaComponent.Mounted[P, S, B], f: P => P): ScalaComponent.Mounted[P, S, B] = {
192+
def modifyProps[P, U <: GenericComponent.Unmounted[P, M], M <: GenericComponent.MountedImpure[P, _]]
193+
(c: GenericComponent[P, CtorType.Props, U], m: M)(f: P => P): M = {
193194
val container = m.getDOMNode.parentNode
194195
val p2 = f(m.props)
195196
c(p2).renderIntoDOM(container.domCast[org.scalajs.dom.raw.Element])
196197
}
197198

198-
def replaceProps[P, S, B](c: ScalaComponent[P, S, B, CtorType.Props])(m: ScalaComponent.Mounted[P, S, B], p: P): ScalaComponent.Mounted[P, S, B] =
199-
modifyProps(c)(m, _ => p)
199+
def replaceProps[P, U <: GenericComponent.Unmounted[P, M], M <: GenericComponent.MountedImpure[P, _]]
200+
(c: GenericComponent[P, CtorType.Props, U], m: M)(p: P): M =
201+
modifyProps(c, m)(_ => p)
200202

201203
private val reactDataAttrRegex = """\s+data-react\S*?\s*?=\s*?".*?"""".r
202204
private val reactTextCommentRegex = """<!-- /?react-text[: ].*?-->""".r

test/src/test/scala/japgolly/scalajs/react/test/TestTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ object TestTest extends TestSuite {
257257
'modifyProps {
258258
ReactTestUtils.withRenderedIntoDocument(CP("start")) { m =>
259259
assertRendered(m.getDOMNode, "<div>none → start</div>")
260-
ReactTestUtils.modifyProps(CP)(m, _ + "ed")
260+
ReactTestUtils.modifyProps(CP, m)(_ + "ed")
261261
assertRendered(m.getDOMNode, "<div>start → started</div>")
262-
ReactTestUtils.replaceProps(CP)(m, "done!")
262+
ReactTestUtils.replaceProps(CP, m)("done!")
263263
assertRendered(m.getDOMNode, "<div>started → done!</div>")
264264
}
265265
}

0 commit comments

Comments
 (0)