[Pkg-javascript-commits] [backbone] 58/74: Adding tests for Backbone.Controller
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:59:09 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.3.0
in repository backbone.
commit 4aafb6b27dd21d67d351de867ada1b4ca729565f
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Mon Nov 8 14:52:30 2010 -0500
Adding tests for Backbone.Controller
---
test/controller.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/test.html | 1 +
2 files changed, 81 insertions(+)
diff --git a/test/controller.js b/test/controller.js
new file mode 100644
index 0000000..bdb5cb0
--- /dev/null
+++ b/test/controller.js
@@ -0,0 +1,80 @@
+$(document).ready(function() {
+
+ module("Backbone.Controller");
+
+ var Controller = Backbone.Controller.extend({
+
+ routes: {
+ "search/:query": "search",
+ "search/:query/p:page": "search",
+ "splat/*args/end": "splat",
+ "*first/complex-:part/*rest": "complex"
+ },
+
+ initialize : function(options) {
+ this.testing = options.testing;
+ },
+
+ search : function(query, page) {
+ this.query = query;
+ this.page = page;
+ },
+
+ splat : function(args) {
+ this.args = args;
+ },
+
+ complex : function(first, part, rest) {
+ this.first = first;
+ this.part = part;
+ this.rest = rest;
+ }
+
+ });
+
+ var controller = new Controller({testing: 101});
+
+ Backbone.history.interval = 9;
+ Backbone.history.start();
+
+ test("Controller: initialize", function() {
+ equals(controller.testing, 101);
+ });
+
+ asyncTest("Controller: routes (simple)", 2, function() {
+ window.location.hash = 'search/news';
+ setTimeout(function() {
+ equals(controller.query, 'news');
+ equals(controller.page, undefined);
+ start();
+ }, 10);
+ });
+
+ asyncTest("Controller: routes (two part)", 2, function() {
+ window.location.hash = 'search/nyc/p10';
+ setTimeout(function() {
+ equals(controller.query, 'nyc');
+ equals(controller.page, '10');
+ start();
+ }, 10);
+ });
+
+ asyncTest("Controller: routes (splats)", function() {
+ window.location.hash = 'splat/long-list/of/splatted_99args/end';
+ setTimeout(function() {
+ equals(controller.args, 'long-list/of/splatted_99args');
+ start();
+ }, 10);
+ });
+
+ asyncTest("Controller: routes (complex)", 3, function() {
+ window.location.hash = 'one/two/three/complex-part/four/five/six/seven';
+ setTimeout(function() {
+ equals(controller.first, 'one/two/three');
+ equals(controller.part, 'part');
+ equals(controller.rest, 'four/five/six/seven');
+ start();
+ }, 10);
+ });
+
+});
diff --git a/test/test.html b/test/test.html
index 67b6cc6..76f1ef1 100644
--- a/test/test.html
+++ b/test/test.html
@@ -12,6 +12,7 @@
<script type="text/javascript" src="events.js"></script>
<script type="text/javascript" src="model.js"></script>
<script type="text/javascript" src="collection.js"></script>
+ <script type="text/javascript" src="controller.js"></script>
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="sync.js"></script>
<script type="text/javascript" src="speed.js"></script>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list