So, I create a service that sends a message to the server to check if a specific email address is in the database.
userDB.emailExists = function()
{
var returnVal;
$http.get('?backend=users&email=myemail%40mydomain.com')
.success(function(data) { returnVal = data.count ? true : false; })
.error(function(data) { });
returnVal = data.count ? true : false;
});
return returnVal;
};
Now there is currently a unit test for this (testing to check if a function returns trueor false) s Expected undefined to be truthy.. I seem to understand why. since the promise returns a "placeholder", so the moment we get to the statement "return" returnValis not yet set.
The only problem is that I do not know how to fix it; I don’t want to return a promise because it seems like an unnecessary layer of complexity when the result is simple true or false