Skip to content

Commit e12351a

Browse files
gzm0sjrd
authored andcommitted
Step 6: Testing
1 parent 8a545f3 commit e12351a

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

build.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ scalaVersion := "2.11.2"
66

77
libraryDependencies += "org.scala-lang.modules.scalajs" %%% "scalajs-jquery" % "0.6"
88

9+
ScalaJSKeys.jsDependencies += scala.scalajs.sbtplugin.RuntimeDOM
10+
911
skip in ScalaJSKeys.packageJSDependencies := false
12+
13+
// uTest settings
14+
utest.jsrunner.Plugin.utestJsSettings
15+
16+
ScalaJSKeys.persistLauncher in Compile := true
17+
18+
ScalaJSKeys.persistLauncher in Test := false

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.6")
2+
3+
addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.3")

scalajs-tutorial-fastopt.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
<title>The Scala.js Tutorial</title>
66
</head>
77
<body>
8-
<button id="click-me-button" type="button">Click me!</button>
9-
108
<!-- Include JavaScript dependencies -->
119
<script type="text/javascript" src="./target/scala-2.11/scala-js-tutorial-jsdeps.js"></script>
1210
<!-- Include Scala.js compiled code -->

src/main/scala/tutorial/webapp/TutorialApp.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ object TutorialApp extends JSApp {
1010
}
1111

1212
def setupUI(): Unit = {
13+
jQuery("""<button type="button">Click me!</button>""")
14+
.click(addClickedMessage _)
15+
.appendTo(jQuery("body"))
1316
jQuery("body").append("<p>Hello World</p>")
14-
jQuery("#click-me-button").click(addClickedMessage _)
1517
}
1618

1719
def addClickedMessage(): Unit = {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package tutorial.webapp
2+
3+
import utest._
4+
5+
import org.scalajs.jquery.jQuery
6+
7+
object TutorialTest extends TestSuite {
8+
9+
// Initialize App
10+
TutorialApp.setupUI()
11+
12+
def tests = TestSuite {
13+
'HelloWorld {
14+
assert(jQuery("p:contains('Hello World')").length == 1)
15+
}
16+
17+
'ButtonClick {
18+
def messageCount =
19+
jQuery("p:contains('You clicked the button!')").length
20+
21+
val button = jQuery("button:contains('Click me!')")
22+
assert(button.length == 1)
23+
assert(messageCount == 0)
24+
25+
for (c <- 1 to 5) {
26+
button.click()
27+
assert(messageCount == c)
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)