[Pkg-javascript-commits] [backbone] 241/281: Fixes #538 -- adds Backbone.history.stop() for unit testers.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:17 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.0
in repository backbone.
commit 96a7274cf746b3aba6ca0b13866d5d5293c3ad82
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Mon Jan 23 10:31:53 2012 -0500
Fixes #538 -- adds Backbone.history.stop() for unit testers.
---
backbone.js | 11 ++++++++++-
test/router.js | 8 +++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/backbone.js b/backbone.js
index 23ff0c7..9926c07 100644
--- a/backbone.js
+++ b/backbone.js
@@ -836,7 +836,7 @@
} else if (this._wantsHashChange && ('onhashchange' in window) && !oldIE) {
$(window).bind('hashchange', this.checkUrl);
} else if (this._wantsHashChange) {
- setInterval(this.checkUrl, this.interval);
+ this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
}
// Determine if we need to change the base url, for a pushState link
@@ -860,6 +860,14 @@
}
},
+ // Disable Backbone.history, perhaps temporarily. Not useful in a real app,
+ // but possibly useful for unit testing Routers.
+ stop: function() {
+ $(window).unbind('popstate', this.checkUrl).unbind('hashchange', this.checkUrl);
+ clearInterval(this._checkUrlInterval);
+ historyStarted = false;
+ },
+
// Add a route to be tested when the fragment changes. Routes added later
// may override previous routes.
route: function(route, callback) {
@@ -898,6 +906,7 @@
// route callback be fired (not usually desirable), or `replace: true`, if
// you which to modify the current URL without adding an entry to the history.
navigate: function(fragment, options) {
+ if (!historyStarted) return false;
if (!options || options === true) options = {trigger: options};
var frag = (fragment || '').replace(routeStripper, '');
if (this.fragment == frag || this.fragment == decodeURIComponent(frag)) return;
diff --git a/test/router.js b/test/router.js
index 8e6202b..79c1931 100644
--- a/test/router.js
+++ b/test/router.js
@@ -117,11 +117,17 @@ $(document).ready(function() {
router.navigate('search/counter', {trigger: true});
router.navigate('counter', {trigger: true});
equal(router.count, 2);
+ Backbone.history.stop();
+ router.navigate('search/counter', {trigger: true});
+ router.navigate('counter', {trigger: true});
+ equal(router.count, 2);
+ Backbone.history.start();
+ equal(router.count, 3);
});
test("Router: use implicit callback if none provided", function() {
router.count = 0;
- router.navigate('implicit', {trigger: true})
+ router.navigate('implicit', {trigger: true});
equal(router.count, 1);
});
--
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