|
18 | 18 | import { expect } from 'chai'; |
19 | 19 |
|
20 | 20 | import { |
| 21 | + DocumentReference, |
21 | 22 | connectFirestoreEmulator, |
22 | 23 | loadBundle, |
23 | 24 | refEqual, |
@@ -71,6 +72,40 @@ describe('DocumentReference', () => { |
71 | 72 | it('JSON.stringify() does not throw', () => { |
72 | 73 | JSON.stringify(documentReference('foo/bar')); |
73 | 74 | }); |
| 75 | + |
| 76 | + it('toJSON() does not throw', () => { |
| 77 | + expect(() => { |
| 78 | + documentReference('foo/bar').toJSON(); |
| 79 | + }).to.not.throw; |
| 80 | + }); |
| 81 | + |
| 82 | + it('toJSON() includes correct JSON fields', () => { |
| 83 | + const docRef = documentReference('foo/bar'); |
| 84 | + const json = docRef.toJSON(); |
| 85 | + expect(json).to.deep.equal({ |
| 86 | + type: 'firestore/documentReference/1.0', |
| 87 | + referencePath: 'foo/bar' |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + it('fromJSON() does not throw', () => { |
| 92 | + const db = newTestFirestore(); |
| 93 | + const docRef = documentReference('foo/bar'); |
| 94 | + const json = docRef.toJSON(); |
| 95 | + expect(() => { |
| 96 | + DocumentReference.fromJSON(db, json); |
| 97 | + }).to.not.throw; |
| 98 | + }); |
| 99 | + |
| 100 | + it('fromJSON() equals original docRef', () => { |
| 101 | + const db = newTestFirestore(); |
| 102 | + const docRef = documentReference('foo/bar'); |
| 103 | + const json = docRef.toJSON(); |
| 104 | + const deserializedDocRef = DocumentReference.fromJSON(db, json); |
| 105 | + expect(docRef.id).to.equal(deserializedDocRef.id); |
| 106 | + expect(docRef.path).to.equal(deserializedDocRef.path); |
| 107 | + expect(docRef.toJSON()).to.deep.equal(deserializedDocRef.toJSON()); |
| 108 | + }); |
74 | 109 | }); |
75 | 110 |
|
76 | 111 | describe('DocumentSnapshot', () => { |
|
0 commit comments