fake_cloud_firestore
fake_cloud_firestore copied to clipboard
Batch operations fail when listening to document changes
(May be a duplicate of #182.)
When I batch create two documents while listening for document changes I see null
document data coming in. The following test fails:
import 'package:fake_cloud_firestore/fake_cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Batch with doc change subscription', () async {
final db = FakeFirebaseFirestore();
final sub = db.collection('docs').snapshots().listen((querySnapshot) {
for (final change in querySnapshot.docChanges) {
debugPrint(
'Change: ${change.doc.id} ${change.type} ${change.doc.data()}');
}
});
addTearDown(sub.cancel);
final batch = db.batch();
batch.set(db.collection('docs').doc('1'), <String, dynamic>{});
batch.set(db.collection('docs').doc('2'), <String, dynamic>{});
await batch.commit();
await pumpEventQueue();
});
}
with
Change: 1 DocumentChangeType.added null
Change: 2 DocumentChangeType.added null
package:fake_cloud_firestore/src/mock_query_document_snapshot.dart 16:27 MockQueryDocumentSnapshot.data
package:fake_cloud_firestore/src/fake_query_with_parent.dart 45:27 _snapshotEquals
... (snip) ...
Null check operator used on a null value
This works if changes are non-batched, or if there's no listen
in place. Tried with latest master
, fails there too.