Closed suztomo closed 4 years ago
documentReference.setData with keys containing dots should create nested documents. Test case to confirm the expected behavior:
documentReference.setData
import 'package:cloud_firestore_mocks/cloud_firestore_mocks.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('Nested documents created by setData with keys containing dots', (WidgetTester tester) async { final fakeFirestore = MockFirestoreInstance()..setupFieldValueFactory(); final documentRef1 = fakeFirestore .collection('users') .document(); final createdTime = DateTime.now(); await documentRef1.setData(<String, dynamic>{ 'favorites.keyA.name': 'Banana', 'favorites.keyA.created': createdTime, }); await documentRef1.setData(<String, dynamic>{ 'favorites.keyB.name': 'Apple', 'favorites.keyB.created': createdTime, }); final snapshot = await documentRef1.get(); expect(snapshot['favorites'], isNotNull); // This fails. final favoritesMap = snapshot['favorites'] as Map<dynamic, dynamic>; expect(favoritesMap.keys as Iterable<String>, hasLength(2)); final bananaMap = favoritesMap['keyA'] as Map<dynamic, dynamic>; expect(bananaMap['name'] as String, 'Banana'); expect(bananaMap['created'] as DateTime, createdTime); }); }
Screenshot from real Firebase (from a different example):
I might contribute a PR to this issue.
I just published your 3 PRs at https://pub.dev/packages/cloud_firestore_mocks#040. Thank you for the great update!
@atn832 Thank you. The enhancement worked well.
documentReference.setData
with keys containing dots should create nested documents. Test case to confirm the expected behavior:Screenshot from real Firebase (from a different example):
I might contribute a PR to this issue.