Created
February 23, 2020 03:47
-
-
Save suztomo/729ace09a54a32649dc2265631363649 to your computer and use it in GitHub Desktop.
cloud_firestore_mocks failure upon FieldValue.serverTimestamp() and FieldValue.delete()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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