Skip to content

Commit bd02333

Browse files
committed
In rare circumstances, Simulation.run targets can go out of date. Targets are now stored by-name.
1 parent 8f1d0ee commit bd02333

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* `ComponentOrNode` moved to test module. Renamed to `ReactOrDomNode`.
44
* Changed overloaded `classSet` methods into `classSet{,1}{,M}`.
55
* Added `simulateKeyDownUp` and `simulateKeyDownPressUp` to `KeyboardEventData` in the test module.
6+
* In rare circumstances, `Simulation.run` targets can go out of date. Targets are now stored by-name.
67

78
# 0.6.0 ([commit log](https://github.com/japgolly/scalajs-react/compare/v0.5.4...v0.6.0))
89

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,26 @@ import ReactTestUtils.Simulate
66
/**
77
* Allows composition and abstraction of `ReactTestUtils.Simulate` procedures.
88
*/
9-
case class Simulation(run: ReactOrDomNode => Unit) {
9+
class Simulation(_run: (() => ReactOrDomNode) => Unit) {
10+
11+
def run(n: => ReactOrDomNode): Unit =
12+
_run(() => n)
1013

1114
def andThen(f: Simulation) =
12-
Simulation(n => { run(n); f.run(n) })
15+
new Simulation(n => { _run(n); f.run(n()) })
1316

1417
@inline final def >> (f: Simulation) = this andThen f
1518
@inline final def compose(f: Simulation) = f andThen this
1619

1720
final def runN(cs: ReactOrDomNode*): Unit =
18-
cs foreach run
21+
cs foreach (run(_))
1922
}
2023

2124
object Simulation {
2225

26+
def apply(run: (=> ReactOrDomNode) => Unit): Simulation =
27+
new Simulation(n => run(n()))
28+
2329
// Don't use default arguments - they force parentheses on to caller.
2430
// Eg. Simulation.blur >> Simulation.focus becomes Simulation.blur() >> Simulation.focus(). Yuk.
2531

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ object TestTest extends TestSuite {
7575
events mustEqual Vector("focus", "change", "blur")
7676
i.getDOMNode().value mustEqual "good"
7777
}
78+
'targetByName {
79+
val c = ReactTestUtils.renderIntoDocument(IC())
80+
var count = 0
81+
def tgt = {
82+
count += 1
83+
Sel("input").findIn(c)
84+
}
85+
Simulation.focusChangeBlur("-") run tgt
86+
assert(count == 3)
87+
}
7888
}
7989
}
8090
}

0 commit comments

Comments
 (0)