const Datastore = require('@google-cloud/datastore');
const datastore = Datastore();
function listTasks(res) {
const query = datastore.createQuery('Test');
datastore.runQuery(query)
.then((results) => {
const tasks = results[0];
tasks.forEach((task) => {
const taskKey = task[datastore.KEY];
console.log(taskKey.id, task);
});
res.send(tasks);
})
.catch((err) => {
console.error('ERROR:', err);
});
}
I want to unittest the above code, but I do not know how to mock/stub the google cloud datastore object/methods. For example, I want to mock/stub datastore.createQuery('Test'), but do not know how.