Skip to content

Commit bb4ca0f

Browse files
committed
feat(refs): resolve non-existant nested refs
1 parent 5d37389 commit bb4ca0f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function subscribeToDocument ({ ref, obj, key, depth, resolve }) {
7979
updateDataFromDocumentSnapshot({ snapshot: createSnapshot(doc), obj, key, subs, depth, resolve })
8080
} else {
8181
obj[key] = null
82+
resolve()
8283
}
8384
})
8485
}

test/bind.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ test('resolves the promise when refs are resolved in a document', async () => {
9999
expect(vm.item).toEqual({ ref: { a: true }})
100100
})
101101

102+
test('resolves the promise when nested refs are resolved in a document', async () => {
103+
const a = db.collection().doc()
104+
const b = db.collection().doc()
105+
await a.update({ a: b })
106+
await b.update({ b: true })
107+
await document.update({ ref: a })
108+
109+
await vm.$bind('item', document)
110+
expect(vm.item).toEqual({ ref: { a: { b: true }}})
111+
})
112+
113+
test('resolves the promise when nested non-existant refs are resolved in a document', async () => {
114+
const a = db.collection().doc()
115+
const b = db.collection().doc()
116+
await a.update({ a: b })
117+
await document.update({ ref: a })
118+
119+
await vm.$bind('item', document)
120+
expect(vm.item).toEqual({ ref: { a: null }})
121+
})
122+
102123
test('resolves the promise when the document does not exist', async () => {
103124
expect(vm.item).toEqual(null)
104125
await vm.$bind('item', document)

0 commit comments

Comments
 (0)