@@ -156,6 +156,37 @@ describe('Firestore refs in documents', async () => {
156156 expect ( data . value ) . toEqual ( { a : aRef . path } )
157157 } )
158158
159+ // https://github.com/vuejs/vuefire/pull/1223
160+ it ( 'sets the path even if the value was null before' , async ( ) => {
161+ const docRef = await addDoc ( listOfRefs , { a : null } )
162+ const { data, pending, promise } = factory ( {
163+ ref : docRef ,
164+ options : { maxRefDepth : 0 } ,
165+ } )
166+
167+ await promise . value
168+ expect ( data . value ) . toEqual ( { a : null } )
169+ await updateDoc ( docRef , { a : aRef } )
170+ expect ( data . value ) . toEqual ( { a : aRef . path } )
171+ } )
172+
173+ it ( 'keeps null for non existent docs refs when updating the doc' , async ( ) => {
174+ const docRef = await addDoc ( listOfRefs , { a : null } )
175+
176+ const { data, promise } = factory ( { ref : docRef } )
177+ await promise . value
178+
179+ expect ( data . value ) . toEqual ( { a : null } )
180+
181+ await updateDoc ( docRef , { a : emptyRef } )
182+
183+ expect ( data . value ) . toEqual ( { a : null } )
184+
185+ await updateDoc ( docRef , { name : 'd' } )
186+
187+ expect ( data . value ) . toEqual ( { a : null , name : 'd' } )
188+ } )
189+
159190 it ( 'does not fail with cyclic refs' , async ( ) => {
160191 const docRef = await addDoc ( listOfRefs , { } )
161192 await setDoc ( docRef , { ref : docRef } )
0 commit comments