From 34207b138736bff595af374b829ec85dd3c0a711 Mon Sep 17 00:00:00 2001 From: Nate Abele Date: Mon, 24 Mar 2014 18:02:27 -0400 Subject: [PATCH] chore($urlRouter): add tests for location syncing --- src/urlRouter.js | 2 +- test/urlRouterSpec.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/urlRouter.js b/src/urlRouter.js index 6c180bfa1..0ad472e6f 100644 --- a/src/urlRouter.js +++ b/src/urlRouter.js @@ -287,7 +287,7 @@ function $UrlRouterProvider( $locationProvider, $urlMatcherFactory) { }, push: function(urlMatcher, params, options) { - $location.url(urlMatcher.format(params)); + $location.url(urlMatcher.format(params || {})); if (options && options.replace) $location.replace(); }, diff --git a/test/urlRouterSpec.js b/test/urlRouterSpec.js index c0cc24fcd..9cd7de370 100644 --- a/test/urlRouterSpec.js +++ b/test/urlRouterSpec.js @@ -106,6 +106,46 @@ describe("UrlRouter", function () { expect(called).toBeTruthy(); expect(location.path()).toBe("/b4z"); })); + + describe("location updates", function() { + it('can push location changes', inject(function($urlRouter, $location) { + spyOn($location, "url"); + spyOn($location, "replace"); + $urlRouter.push(new UrlMatcher("/hello/:name"), { name: "world" }); + + expect($location.url).toHaveBeenCalledWith("/hello/world"); + expect($location.replace).not.toHaveBeenCalled(); + })); + + it('can push a replacement location', inject(function($urlRouter, $location) { + spyOn($location, "url"); + spyOn($location, "replace"); + $urlRouter.push(new UrlMatcher("/hello/:name"), { name: "world" }, { replace: true }); + + expect($location.url).toHaveBeenCalledWith("/hello/world"); + expect($location.replace).toHaveBeenCalled(); + })); + + it('can push location changes with no parameters', inject(function($urlRouter, $location) { + spyOn($location, "url"); + $urlRouter.push(new UrlMatcher("/hello/:name")); + + expect($location.url).toHaveBeenCalledWith("/hello/"); + })); + + it('can read and sync a copy of location URL', inject(function($urlRouter, $location) { + $location.url('/old'); + + spyOn($location, 'url').andCallThrough(); + $urlRouter.update(true); + expect($location.url).toHaveBeenCalled(); + + $location.url('/new'); + $urlRouter.update(); + + expect($location.url()).toBe('/old'); + })); + }); }); }); \ No newline at end of file