I have a function like this
module.exports = function() {
return new BPromise(function (resolve, reject) {
analytics.management.accountSummaries.list({}, function (err, results) {
if (err !== null) {
reject(new Error(err));
} else {
resolve(profileId);
}
});
});
}
and here is the test
const analytics = require('googleapis').analytics({version: 'v3'}),
stub = sinon
.mock(analytics.management.accountSummaries)
.expects('list')
.once()
.yields(null, dummy);
analyticsService.getProfileFromTracker('UA-3213-321')
.then(function () {
stub.verify();
done();
})
.catch(Error, function (err) {
stub.verify();
done();
});
But the stubbed function will never run. What am I doing wrong.
Thanx guys
Greetings! I know this issue has been around for a while, but with the latest versions of sinon and googleapis, this works great!
const {google} = require('googleapis');
const sinon = require('sinon');
const analytics = google.analytics('v3');
const stub = sinon
.mock(analytics.management.accountSummaries)
.expects('list')
.once()
.resolves({});
analytics.management.accountSummaries.list()
.then(r => console.log(r))
.catch(e => console.error(e));
Please do let us know if you have any other questions :)
Most helpful comment
Greetings! I know this issue has been around for a while, but with the latest versions of
sinonandgoogleapis, this works great!Please do let us know if you have any other questions :)