9
サービスのジャスミンユニットテストを実行しようとしています。私は$の場所を嘲笑が、エラーを取得していますTypeErrorを解決するには:spyOn andReturnは関数ではありませんか?
app.factory('testService', function($location) {
return {
config: function() {
var host = $location.absUrl();
var result = '';
if (host.indexOf('localhost') >= 0) {
return 'localhost'
}
if (host.indexOf('myserver') >= 0) {
return 'myserver'
}
}
};
});
私のテストでは、次のようになります。 はTypeError::spyOn(...)
describe('testing service', function() {
var configService, $rootScope, $location;
beforeEach(module('myApp'));
beforeEach(inject(function (_$location_) {
//$rootScope = _$rootScope_;
$location = _$location_;
//configService=_configService_;
spyOn($location, 'absUrl').andReturn('localhost');
}));
it('should return something ', function() {
inject(function (configService) {
//expect($location.absUrl).toHaveBeenCalled();
//expect($rootScope.absUrl()).toBe('localhost');
var result= configService.config($location);
expect(result).toBe('localhost');
});
});
});
これは私が取得していますエラーです。 andReturnは関数ではありませんか?