Angularjs Angular spyon location.path在单元测试中不起作用
角度控制器:Angularjs Angular spyon location.path在单元测试中不起作用,angularjs,Angularjs,角度控制器: function Controller($location, someservice){ $location.path(someservice.getPath()); } 单元测试: describe("Controller unit testing",function(){ beforeEach(inject(function (_$controller_, _$location_) { $location = _$location_; // Mock
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');
});
}
在这方面,第二个期望是失败的。有人能帮我解决吗