vendredi 20 mars 2015

Why does $route have to be included in unit testing $location only?

I wanted to write a unit test to confirm my "otherwise" logic was working correctly. This is how I expected to do it:



it('should handle unknown routes properly', inject(function($location, $rootScope) {
$location.path('/unknown');

$rootScope.$digest();

expect(location.path()).toBe('/yikes');
}));


However, what I discovered is that I had to inject $route to make this test work. Keep in mind, the unit test code didn't have to use $route but apparently it needed to be instantiated to make $location work properly.


Here's a plunkr if you're interested in more details.


I see lots of discussion that seems to be related:



Aucun commentaire:

Enregistrer un commentaire