In below example I want to mock dataService.The problem is I need to test the functionality after the data is returned under function(data).
As the logic is dependent on the data returned.I think mocking/Spying the dataservice
might not help in this regard.
Kindly provide the probable solution.
var app = angular.module('app', []);
app.controller('Controller', ['$scope', '$location', 'dataService', '$window', 'OtherService', 'Config', function ($scope, $location, dataService, $window, SomeService, Config) {
$scope.btnClick = function () {
var SomeNumber = $scope.enteredNumber;
if (SomeNumber == "xyz") {
$scope.errorType = 'errorRequired';
}
else {
dataService.validate_enteredNumber(SomeNumber, function (data) {
if (data != null) {
if (data.responsetype == 1) {
$scope.errortype = data.responsemessage;
}
else {
dataservice.getdetailsforenterednumber(data.responsemessage, function (getdata) {
if (getdata.responsetype == 1) {
$scope.errortype = getdata.responsemessage;
}
else if (getdata.responsetype == 2) {
if (getdata.responsemessage.touppercase() == "consumer")
$window.location.href = "url";
}
else
$location.path('/Somelist').search({ SomeNumber: getdata.responsemessage });
});
}
}
});
}
}
if ($location.search().SomeNumber != null) {
$scope.enteredNumber = $location.search().SomeNumber;
$scope.btnClick();
}
} ]);
Aucun commentaire:
Enregistrer un commentaire