From 8d8a3599a912c206b205ee3ad48c8b5fbe9fa6c3 Mon Sep 17 00:00:00 2001 From: Sam Breed Date: Tue, 14 Feb 2012 23:17:08 -0700 Subject: [PATCH] adding test coverage for route precedence as per issue #996 --- test/router.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/router.js b/test/router.js index 989eb026..c0d5ce78 100644 --- a/test/router.js +++ b/test/router.js @@ -11,6 +11,9 @@ $(document).ready(function() { "counter": "counter", "search/:query": "search", "search/:query/p:page": "search", + "contacts": "contacts", + "contacts/new": "newContact", + "contacts/:id": "loadContact", "splat/*args/end": "splat", "*first/complex-:part/*rest": "complex", ":entity?*args": "query", @@ -35,6 +38,18 @@ $(document).ready(function() { this.page = page; }, + contacts: function(){ + this.contact = 'index'; + }, + + newContact: function(){ + this.contact = 'new'; + }, + + loadContact: function(){ + this.contact = 'load'; + }, + splat : function(args) { this.args = args; }, @@ -107,6 +122,18 @@ $(document).ready(function() { equal(router.page, '20'); }); + test("Router: route precedence via navigate", 6, function(){ + // check both 0.9.x and backwards-compatibility options + _.each([ { trigger: true }, true ], function( options ){ + Backbone.history.navigate('contacts', options); + equal(router.contact, 'index'); + Backbone.history.navigate('contacts/new', options); + equal(router.contact, 'new'); + Backbone.history.navigate('contacts/foo', options); + equal(router.contact, 'load'); + }); + }); + test("Router: doesn't fire routes to the same place twice", function() { equal(router.count, 0); router.navigate('counter', {trigger: true});