Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('waits for all refs in document with interrupting by new ref', async () => {
const a = db.collection().doc()
// @ts-ignore
const b: firestore.DocumentReference = db.collection().doc()
const c = db.collection().doc()
delayUpdate(b)
await document.update({ a, b })
const promise = vm.$bind('item', document)
document.update({ c })
await promise
expect(vm.item).toEqual({
a: null,
b: null,
c: null,
})
})
it('waits for all refs in document with interrupting by new ref', async () => {
const a = db.collection().doc()
// @ts-ignore
const b: firestore.DocumentReference = db.collection().doc()
const c = db.collection().doc()
delayUpdate(b)
await document.update({ a, b })
const promise = setItem(document)
document.update({ c })
await promise
expect(store.state.item).toEqual({
a: null,
b: null,
c: null,
})
})
it('waits for nested refs with data in collections', async () => {
const a = db.collection().doc()
// @ts-ignore
const b: firestore.DocumentReference = db.collection().doc()
// @ts-ignore
const c: firestore.DocumentReference = db.collection().doc()
await a.update({ isA: true })
await c.update({ isC: true })
await b.update({ c })
delayUpdate(b)
delayUpdate(c, 5)
await collection.add({ a })
await collection.add({ b })
await setItems(collection)
expect(store.state.items).toEqual([{ a: { isA: true } }, { b: { c: { isC: true } } }])
})
it('waits for nested refs in collections', async () => {
const a = db.collection().doc()
// @ts-ignore
const b: firestore.DocumentReference = db.collection().doc()
// @ts-ignore
const c: firestore.DocumentReference = db.collection().doc()
await b.update({ c })
delayUpdate(b)
delayUpdate(c, 5)
await collection.add({ a })
await collection.add({ b })
await vm.$bind('items', collection)
expect(vm.items).toEqual([{ a: null }, { b: { c: null } }])
})
it('waits for array to be fully populated', async () => {
const c = db.collection().doc()
await c.update({ isC: true })
await collection.add({ ref: c })
// force callback delay
// @ts-ignore
delayUpdate(c)
const data = await bind('items', collection)
expect(data).toEqual(vm.items)
expect(vm.items).toEqual([
{ ref: { isA: true } },
{ ref: { isB: true } },
{ ref: { isC: true } },
])
})