Skip to content

Instantly share code, notes, and snippets.

@djbriane
Created November 2, 2012 04:22
Show Gist options
  • Save djbriane/3998698 to your computer and use it in GitHub Desktop.
Save djbriane/3998698 to your computer and use it in GitHub Desktop.
Backbone.js - Tests for Route with Trailing Spaces
test("#XXXX Trailing spaces (pushState:false).", 1, function() {
var count = 0;
Backbone.history.stop();
// restart History with pushState:false
Backbone.history.start({
pushState: false
});
router.on("route:search", function(page) {
count = count + 1;
});
// navigate to the search route with trailing space in the query string
Backbone.history.navigate('search/space ', {trigger: true});
// manually fire checkUrl
Backbone.history.checkUrl();
equal(count, 1); // route event should be fired once
router.off("route:search"); //unbind events
});
test("#XXXX Trailing spaces using browser location (pushState: false).", 1, function() {
var count = 0;
Backbone.history.stop();
Backbone.history.location = window.location; // Use browser location
// restart History with pushState:false
Backbone.history.start({
pushState: false
});
router.on("route:search", function(page) {
count = count + 1;
});
// navigate to the search route with trailing space in the query string
Backbone.history.navigate('search/space ', {trigger: true});
// manually fire checkUrl
Backbone.history.checkUrl();
equal(count, 1); // route event should be fired only once
router.off("route:search"); //unbind events
// restore location hash
window.location.hash = '';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment