角度控制器:
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');
});
}
在此,第二个期望是失败。有人可以帮我解决吗?