I have to write a test-case using karma to the following code.
$scope.getUserDetails = function (param) {
Api.getData(param).then(function (result) {
Api.getVal(result).then(function (data) {
var display = Api.userDetails(result.id, result.name);
$scope.username = display.name;
});
});
};
But i am facing the problem because of test case fails due to missing parameter from call-back function. I tried many methods. But test-cases failed due to result.id is undefined. Following is just a scaffold of my test-case. 'apiCall' are defined in beforeEach.
it('should test the getData()', function () {
var user = 'John';
scope.getUserDetails(123);
deferred.resolve(user);
spyOn(apiCall, 'getData').and.returnValue(deferred.promise);
});