0
は、どのように私はモックとすることができますユニットテストのカルマ/ジャスミン
I have an angular factory which again calls another factory- service that uses $resource for API call. Could someone tell me, How can I mock and test this kind of constructs.
//factory
angular.module('myapp')
.factory('SampleF', function (SampleS) {
return {
getData: function (parm, callback) {
var cb = callback || angular.noop;
return SampleS.get(parm,
function (res) {
return cb(res);
},
function (err) {
return cb(err);
}.bind(this)).$promise;
}
};
});
// Service: SampleS
angular.module('myapp')
.factory('SampleS', function ($resource) {
return $resource('http://localhost:8080:/api/sample/:parm', {
parm: '@parm',
}, {});
});
//API response will be
` {
"firstName": "John",
"lastName": "Franklin",
"companyName": "Benton, John B Jr",
"address": "6649 N Blue Gum St",
"city": "New Oakland",
"county": "Oakland",
"statie": "LA",
"zip": "703333",
"phone": "503-321-2227",
"phone2": "514-145-427",
"email": "[email protected]",
}