Skip to content

Commit

Permalink
chore($urlRouter): add tests for location syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
nateabele committed Mar 24, 2014
1 parent 3a03042 commit 34207b1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/urlRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},

Expand Down
40 changes: 40 additions & 0 deletions test/urlRouterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}));
});
});

});

0 comments on commit 34207b1

Please sign in to comment.