Setting $location.search on AngularJS unit tests

481 Views Asked by At

For some reason when I try to set param with...

$location.search('id', 2);

... on AngularJS unit tests (Karma + PhantomJS), it doesn't set, even with $apply set. And if I test it straight away...

expect($location.search().id).toEqual(2);

... it would give me that ID is undefined.

Am I doing something wrong?

1

There are 1 best solutions below

1
On

Try spy

 spyOn($location, 'search').and.returnValue({
        id:2
    });