Last active
November 18, 2020 19:21
-
-
Save utkarsh-UK/d2cdd40cfae5ee21b8c0cffeaef04ef7 to your computer and use it in GitHub Desktop.
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'; | |
class MockFirestore extends Mock implements FirebaseFirestore {} | |
class MockCollectionReference extends Mock implements CollectionReference {} | |
class MockDocumentReference extends Mock implements DocumentReference {} | |
class MockDocumentSnapshot extends Mock implements DocumentSnapshot {} | |
void main() { | |
MockFirestore instance; | |
MockDocumentSnapshot mockDocumentSnapshot; | |
MockCollectionReference mockCollectionReference; | |
MockDocumentReference mockDocumentReference; | |
setUp(() { | |
instance = MockFirestore(); | |
mockCollectionReference = MockCollectionReference(); | |
mockDocumentReference = MockDocumentReference(); | |
mockDocumentSnapshot = MockDocumentSnapshot(); | |
}); | |
test('should return data when the call to remote source is successful.', () async { | |
when(instance.collection(any)).thenReturn(mockCollectionReference); | |
when(mockCollectionReference.doc(any)).thenReturn(mockDocumentReference); | |
when(mockDocumentReference.get()).thenAnswer((_) async => mockDocumentSnapshot); | |
when(mockDocumentSnapshot.data()).thenReturn(responseMap); | |
//act | |
final result = await remoteDataSource.getData('user_id'); | |
//assert | |
expect(result, userModel); //userModel is a object that is defined. Replace with you own model class object. | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment