在AngularJS单元测试中设置$ location.search

时间:2015-06-12 15:39:46

标签: angularjs unit-testing phantomjs karma-runner

由于某种原因,当我尝试用...设置参数时。

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

...在AngularJS单元测试(Karma + PhantomJS)上,即使使用$ apply set也不会设置。如果我马上测试它......

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

...它会让我ID未定义。

我做错了吗?

1 个答案:

答案 0 :(得分:0)

尝试间谍

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