Let's suppose, we have an angular service that has a function as follows:
this.getAllBranches = function () {
var deferred = $q.defer();
db.transaction(function (tx) {
tx.executeSql("select * from branch", [], function (tx, res) {
var branchList = [];
for (var i = 0; i < res.rows.length; i++) {
var branch = {};
branch.id = res.rows.item(i).id;
branch.code = res.rows.item(i).code;
branch.address = res.rows.item(i).address;
branch.city = res.rows.item(i).city;
branch.state = res.rows.item(i).state;
branch.zip = res.rows.item(i).zip;
branchList.push(branch);
}
deferred.resolve(branchList);
}, function (t, e) {
alert('An error occurred getting list of branches.');
deferred.reject(e);
});
});
return deferred.promise;
};
How do we test the above function?
Aucun commentaire:
Enregistrer un commentaire