summaryrefslogtreecommitdiff
path: root/examples/testing
diff options
context:
space:
mode:
Diffstat (limited to 'examples/testing')
-rw-r--r--examples/testing/src/main/scala/ElementCreator.scala7
-rw-r--r--examples/testing/src/test/scala/CollectionTest.scala17
-rw-r--r--examples/testing/src/test/scala/ElementCreatorTest.scala24
-rw-r--r--examples/testing/testing-2.10-fastopt.html32
-rw-r--r--examples/testing/testing-2.10.html32
-rw-r--r--examples/testing/testing-2.11-fastopt.html32
-rw-r--r--examples/testing/testing-2.11.html32
7 files changed, 176 insertions, 0 deletions
diff --git a/examples/testing/src/main/scala/ElementCreator.scala b/examples/testing/src/main/scala/ElementCreator.scala
new file mode 100644
index 0000000..ccb3600
--- /dev/null
+++ b/examples/testing/src/main/scala/ElementCreator.scala
@@ -0,0 +1,7 @@
+import scala.scalajs.js.Dynamic.global
+
+object ElementCreator {
+ val jQ = global.jQuery
+
+ def create() = jQ("body").append(jQ("<h1>Test</h1>"))
+}
diff --git a/examples/testing/src/test/scala/CollectionTest.scala b/examples/testing/src/test/scala/CollectionTest.scala
new file mode 100644
index 0000000..a586ca2
--- /dev/null
+++ b/examples/testing/src/test/scala/CollectionTest.scala
@@ -0,0 +1,17 @@
+import scala.scalajs.js
+import scala.scalajs.js.Dynamic.global
+import scala.scalajs.js.JSConverters._
+
+import org.scalajs.jasminetest.JasmineTest
+
+object CollectionTest extends JasmineTest {
+
+ describe("Array") {
+
+ it("should be able to map and filter integers") {
+ val array = Array(5, 7, 2, 6, -30, 33, 66, 76, 75, 0)
+ val result = array.filter(_.toInt % 3 != 0).map(x => x*x)
+ expect(result.toJSArray).toEqual(js.Array(25, 49, 4, 76*76))
+ }
+ }
+}
diff --git a/examples/testing/src/test/scala/ElementCreatorTest.scala b/examples/testing/src/test/scala/ElementCreatorTest.scala
new file mode 100644
index 0000000..43f6756
--- /dev/null
+++ b/examples/testing/src/test/scala/ElementCreatorTest.scala
@@ -0,0 +1,24 @@
+import scala.scalajs.js
+import scala.scalajs.js.Dynamic.global
+
+import org.scalajs.jasminetest.JasmineTest
+
+object ElementCreatorTest extends JasmineTest {
+
+ describe("ElementCreator") {
+
+ it("should be able to create an element in the body") {
+ // create the element
+ ElementCreator.create()
+
+ // jquery would make this easier, but I wanted to
+ // only use pure html in the test itself
+ val body = global.document.getElementsByTagName("body")
+ .asInstanceOf[js.Array[js.Dynamic]].head
+
+ // the Scala.js DOM API would make this easier
+ expect(body.lastChild.tagName.toString == "H1").toBeTruthy
+ expect(body.lastChild.innerHTML.toString == "Test").toBeTruthy
+ }
+ }
+}
diff --git a/examples/testing/testing-2.10-fastopt.html b/examples/testing/testing-2.10-fastopt.html
new file mode 100644
index 0000000..04ded2f
--- /dev/null
+++ b/examples/testing/testing-2.10-fastopt.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Testing - Jasmine HTML reporter example</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.css"></link>
+</head>
+<body>
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine-html.js"></script>
+<script type="text/javascript" src="./target/scala-2.10/testing-test-fastopt.js"></script>
+
+<script type="text/javascript">
+$(function() {
+ // Load tests
+ CollectionTest();
+ ElementCreatorTest();
+
+ // Setup and run Jasmine
+ var jasmineEnv = jasmine.getEnv();
+ var htmlReporter = new jasmine.HtmlReporter();
+ jasmineEnv.addReporter(htmlReporter);
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+ jasmineEnv.execute();
+});
+</script>
+
+</body>
+</html>
diff --git a/examples/testing/testing-2.10.html b/examples/testing/testing-2.10.html
new file mode 100644
index 0000000..bbb0cfe
--- /dev/null
+++ b/examples/testing/testing-2.10.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Testing - Jasmine HTML reporter example</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.css"></link>
+</head>
+<body>
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine-html.js"></script>
+<script type="text/javascript" src="./target/scala-2.10/testing-test-opt.js"></script>
+
+<script type="text/javascript">
+$(function() {
+ // Load tests
+ CollectionTest();
+ ElementCreatorTest();
+
+ // Setup and run Jasmine
+ var jasmineEnv = jasmine.getEnv();
+ var htmlReporter = new jasmine.HtmlReporter();
+ jasmineEnv.addReporter(htmlReporter);
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+ jasmineEnv.execute();
+});
+</script>
+
+</body>
+</html>
diff --git a/examples/testing/testing-2.11-fastopt.html b/examples/testing/testing-2.11-fastopt.html
new file mode 100644
index 0000000..a87f635
--- /dev/null
+++ b/examples/testing/testing-2.11-fastopt.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Testing - Jasmine HTML reporter example</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.css"></link>
+</head>
+<body>
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine-html.js"></script>
+<script type="text/javascript" src="./target/scala-2.11/testing-test-fastopt.js"></script>
+
+<script type="text/javascript">
+$(function() {
+ // Load tests
+ CollectionTest();
+ ElementCreatorTest();
+
+ // Setup and run Jasmine
+ var jasmineEnv = jasmine.getEnv();
+ var htmlReporter = new jasmine.HtmlReporter();
+ jasmineEnv.addReporter(htmlReporter);
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+ jasmineEnv.execute();
+});
+</script>
+
+</body>
+</html>
diff --git a/examples/testing/testing-2.11.html b/examples/testing/testing-2.11.html
new file mode 100644
index 0000000..9902c3f
--- /dev/null
+++ b/examples/testing/testing-2.11.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Testing - Jasmine HTML reporter example</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.css"></link>
+</head>
+<body>
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.js"></script>
+<script type="text/javascript" src="http://cdn.jsdelivr.net/jasmine/1.3.1/jasmine-html.js"></script>
+<script type="text/javascript" src="./target/scala-2.11/testing-test-opt.js"></script>
+
+<script type="text/javascript">
+$(function() {
+ // Load tests
+ CollectionTest();
+ ElementCreatorTest();
+
+ // Setup and run Jasmine
+ var jasmineEnv = jasmine.getEnv();
+ var htmlReporter = new jasmine.HtmlReporter();
+ jasmineEnv.addReporter(htmlReporter);
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+ jasmineEnv.execute();
+});
+</script>
+
+</body>
+</html>