Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d144be0

Browse files
gzm0sjrd
authored andcommitted
Step 6: Testing
1 parent 0296d63 commit d144be0

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

build.sbt

+7
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ scalaVersion := "2.13.3"
77
scalaJSUseMainModuleInitializer := true
88

99
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "1.1.0"
10+
11+
// Add support for the DOM in `run` and `test`
12+
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
13+
14+
// uTest settings
15+
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.7.4" % "test"
16+
testFrameworks += new TestFramework("utest.runner.Framework")

project/plugins.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.0")
2+
3+
libraryDependencies += "org.scala-js" %% "scalajs-env-jsdom-nodejs" % "1.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package tutorial.webapp
2+
3+
import utest._
4+
5+
import scala.scalajs.js
6+
7+
import org.scalajs.dom
8+
import org.scalajs.dom.document
9+
import org.scalajs.dom.ext._
10+
11+
object TutorialTest extends TestSuite {
12+
13+
// Initialize App
14+
TutorialApp.setupUI()
15+
16+
def tests = Tests {
17+
test("HelloWorld") {
18+
assert(document.querySelectorAll("p").count(_.textContent == "Hello World") == 1)
19+
}
20+
21+
test("ButtonClick") {
22+
def messageCount =
23+
document.querySelectorAll("p").count(_.textContent == "You clicked the button!")
24+
25+
val button = document.querySelector("button").asInstanceOf[dom.html.Button]
26+
assert(button != null && button.textContent == "Click me!")
27+
assert(messageCount == 0)
28+
29+
for (c <- 1 to 5) {
30+
button.click()
31+
assert(messageCount == c)
32+
}
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)