Skip to content

Instantly share code, notes, and snippets.

@suztomo
Created February 23, 2020 03:47
Show Gist options
  • Save suztomo/729ace09a54a32649dc2265631363649 to your computer and use it in GitHub Desktop.
Save suztomo/729ace09a54a32649dc2265631363649 to your computer and use it in GitHub Desktop.
cloud_firestore_mocks failure upon FieldValue.serverTimestamp() and FieldValue.delete()
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore_mocks/cloud_firestore_mocks.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('FieldValue.serverTimestamp does not work',
(WidgetTester tester) async {
final fakeFirestore = MockFirestoreInstance();
// Application initial status. 2 users Bob (aaabbcc) and irrelevantUserId
final subcollectionRef = fakeFirestore
.collection('users')
.document('qwpeoivjkasdu')
.collection('notes');
await subcollectionRef.document('foobar')
.setData(<String, dynamic>{
'content': 'MockFirestoreInstance is great',
'createdBy': 'Tomo',
// 'created': FieldValue.serverTimestamp(), // type 'MethodChannelFieldValue' is not a subtype of type 'MockFieldValuePlatform' in type cast
});
await subcollectionRef.document('foobar')
.setData(<String, dynamic>{
'content': FieldValue.delete() // type 'MethodChannelFieldValue' is not a subtype of type 'MockFieldValuePlatform' in type cast
});
final retrievedNotes = await subcollectionRef.getDocuments();
for (final snapshot in retrievedNotes.documents) {
expect(snapshot['content'], 'MockFirestoreInstance is great');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment