I'm using AngularJS and my tests are in mocha+sinon+chai
The code I'm trying to test looks like this:
addModal.result.then(function (clientFeature) {
if (clientFeature) {
//create a new $resource ClientFeature object with result
var newClientFeature = new ClientFeature(clientFeature);
//push newly created clientfeature to list
$scope.clientFeatures.push(newClientFeature);
//make REST call to create new clientfeature
newClientFeature.$save({clientId: newClientFeature.client.id}, function (data, headers) {
console.log('created.');
console.log(data);
}, null);
}
});
ClientFeature is a $resource object:
'use strict';
angular.module('yrdyApp')
.factory('ClientFeature', function ($resource, $location) {
return $resource('https://' + $location.host() + ':port/clientfeatures/client/:clientId', {port: ':3333', clientId: '@clientId'}, {
update: {method: 'PUT'}
});
});
How do I mock out this line?
//create a new $resource ClientFeature object with result
var newClientFeature = new ClientFeature(clientFeature);
My existing mocks:
// set up mocks
ClientFeatureMock = {
query: sinon.spy(),
update: sinon.stub()
};
// mock client feature object
clientFeature = {
client: {
id: 100
},
$update: sinon.spy(),
$save: sinon.spy()
};
Thanks, Shaun