I have a simple angular service which calls a method (this.updateVariable), parses the value received, and updates a variable (myString) with a string.
I want to understand how can i write a unit test to test if the value received is updating a variable with the correct string.
Service:
app.service('myService', function() {
this.updateVariable = function (status, data) {
var myString = '';
if (status.toString()[0] == 4 && data.message !== undefined) {
if ((data.message.indexOf("Out of spoons") > -1) || (data.message.indexOf("Out of forks")) > -1){
myString = "Sorry, weve ran out of spoons and/or forks";
}
else if (data.message.indexOf("Out of plates") > -1) {
myString = "Sorry, weve ran out of plates";
}
else {
myString = "We seem to be facing a technical issue";
}
}
if (status.toString()[0] == 9) {
myString = "Ooops, looks like something is broke.";
}
return myString;
};
});