File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed
main/scala/scommons/react/test/dom
test/scala/scommons/react/test/dom Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -78,4 +78,18 @@ trait AsyncTestSpec extends AsyncFlatSpec
7878
7979 promise.future
8080 }
81+
82+ def executeAfterDelay (millis : Int )(block : => Assertion ): Future [Assertion ] = {
83+ val promise = Promise [Assertion ]()
84+
85+ dom.window.setTimeout({ () =>
86+ try {
87+ promise.success(block)
88+ } catch {
89+ case NonFatal (ex) => promise.failure(ex)
90+ }
91+ }, millis.toDouble)
92+
93+ promise.future
94+ }
8195}
Original file line number Diff line number Diff line change @@ -26,10 +26,40 @@ class AsyncTestSpecTest extends AsyncTestSpec {
2626 // given
2727 val value = 5
2828
29+ // when
30+ val resultF = eventually {
31+ value shouldBe 1
32+ }
33+
34+ // then
35+ resultF.failed.map { result =>
36+ result.getMessage should include (" 5 was not equal to 1" )
37+ }
38+ }
39+
40+ it should " run successfully after delay when executeAfterDelay" in {
41+ // given
42+ val delay = 500
43+ val value = 5
44+
2945 // when & then
30- eventually {
46+ executeAfterDelay(delay) {
47+ value shouldBe 5
48+ }
49+ }
50+
51+ it should " fail if not succeeded after delay when executeAfterDelay" in {
52+ // given
53+ val delay = 500
54+ val value = 5
55+
56+ // when
57+ val resultF = executeAfterDelay(delay) {
3158 value shouldBe 1
32- }.failed.map { result =>
59+ }
60+
61+ // then
62+ resultF.failed.map { result =>
3363 result.getMessage should include (" 5 was not equal to 1" )
3464 }
3565 }
You can’t perform that action at this time.
0 commit comments