Skip to content

Commit df592c5

Browse files
committed
Attempt to fix flakey async unit test
- Use ReactTestUtils.withRendered instead of withRendered_ to keep the component mounted during the delay. - Wrap form interaction and delayMs inside ReactTestUtils.act to correctly flush concurrent React updates/transitions during testing.
1 parent d034cb8 commit df592c5

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

  • library/tests/src/test/scala/japgolly/scalajs/react/core/vdom

library/tests/src/test/scala/japgolly/scalajs/react/core/vdom/VdomTest.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,15 @@ object VdomTest extends AsyncTestSuite {
208208
)
209209
}
210210

211-
ReactTestUtils.withRendered_(comp()) { t =>
212-
val form = t.asHtml()
213-
form.querySelector("input").asInstanceOf[html.Input].value = "scalajs-react"
214-
val button = form.querySelector("button").asInstanceOf[html.Button]
215-
Simulate.click(button)
216-
}.delayMs(50).map { _ =>
211+
ReactTestUtils.withRendered(comp()) { t =>
212+
ReactTestUtils.act {
213+
val form = t.asHtml()
214+
form.querySelector("input").asInstanceOf[html.Input].value = "scalajs-react"
215+
val button = form.querySelector("button").asInstanceOf[html.Button]
216+
Simulate.click(button)
217+
AsyncCallback.unit.delayMs(50)
218+
}
219+
}.map { _ =>
217220
assertEq(query, "scalajs-react")
218221
}
219222
}

0 commit comments

Comments
 (0)