Angular spyon location.path在单元测试中不起作用

时间:2015-03-10 12:24:40

标签: angularjs

角度控制器:

function Controller($location, someservice){
   $location.path(someservice.getPath());
}

单元测试:

describe("Controller unit testing",function(){
beforeEach(inject(function (_$controller_, _$location_) {
    $location = _$location_;

    // Mock someservice
    someservicemock= {

      getPath: function () { return "/somepath";},
    };

    controller = _$controller_("Controller", { $location: $location, someservice: someservicemock});
    spyOn(someservicemock, "getPath");
  }));

it("should redirect to other path", function () {

    // Assert
    expect(someservicemock.getPath).toHaveBeenCalled();
    expect($location.path()).toBe('/somepath');
  });

}

在此,第二个期望是失败。有人可以帮我解决吗?

0 个答案:

没有答案