Say I define a factory as follows:
angular.module('myServices').factory('TestService', ['Restangular',
function(restangular){
return restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl('api');
RestangularConfigurer.setRestangularFields({ id: 'Id'});
};
}).all('Job');
}]);
I would like to be able to write unit tests to confirm that my baseUrl
and the id
field has been set correctly. Is this possible? I know I can view the route with the .route
property on my service but that doesn't include the baseUrl
.
Late response I know, but I was wondering this myself and couldn't find a definite answer. The returned object has a 'configuration' property, which has 'baseUrl' and 'restangularFields' properties.
I'd also suggest moving the custom Restangular object into its own service:
angular.module('myServices')
.factory('TestService',
['Restangular',
function(restangular) {
return restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl('api');
RestangularConfigurer.setRestangularFields({ id: 'Id'});
});
}
])
.factory('Job',
['TestService',
function (TestService) {
return TestService.all('Job');
}
]);
So you could test like so:
//sut is 'system under test', in your case the TestService
expect(sut.configuration.baseUrl).toEqual('api');
expect(sut.configuration.restangularFields.id).toEqual('id');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With