Skip to content

Commit 040a492

Browse files
authored
Merge pull request soumak77#96 from Storr-co/run-transaction-return-value
Update Firestore.runTransaction to resolve promise with returned value
2 parents e379b23 + 171bb39 commit 040a492

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/firestore.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ MockFirestore.prototype.runTransaction = function(transFunc) {
7272
return doc.get();
7373
};
7474
return new Promise(function(resolve, reject) {
75-
transFunc(batch).then(function() {
76-
batch.commit().then(resolve).catch(reject);
75+
Promise.resolve(transFunc(batch)).then(function(value) {
76+
batch
77+
.commit()
78+
.then(function () {
79+
resolve(value);
80+
})
81+
.catch(reject);
7782
}).catch(reject);
7883
});
7984
};

test/unit/firestore.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ describe('MockFirestore', function () {
134134
}).catch(done);
135135
}).catch(done);
136136
});
137+
138+
it('returns the return value of the passed function', function () {
139+
db.autoFlush();
140+
141+
return db.runTransaction(function(transaction) {
142+
return transaction.get(db.doc('doc')).then(function() {
143+
return 'cba';
144+
});
145+
}).then(function(transactionReturn) {
146+
expect(transactionReturn).to.equal('cba');
147+
});
148+
});
137149
});
138150

139151
describe('#batch', function () {

0 commit comments

Comments
 (0)