diff --git a/mockfirestore/document.py b/mockfirestore/document.py index 24aa433..808959f 100644 --- a/mockfirestore/document.py +++ b/mockfirestore/document.py @@ -23,6 +23,8 @@ def exists(self) -> bool: return self._doc != {} def to_dict(self) -> Document: + if not self.exists: + return None return self._doc @property diff --git a/tests/test_document_reference.py b/tests/test_document_reference.py index c582b36..d3ff43c 100644 --- a/tests/test_document_reference.py +++ b/tests/test_document_reference.py @@ -52,7 +52,7 @@ def test_document_get_documentDoesNotExist(self): fs = MockFirestore() fs._data = {'foo': {}} doc = fs.collection('foo').document('bar').get().to_dict() - self.assertEqual({}, doc) + self.assertIsNone(doc) def test_get_nestedDocument(self): fs = MockFirestore()