Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('unbinds previously bound document when overwriting a bound', async () => {
// Mock c onSnapshot to spy when the callback is called
const spy = spyOnSnapshotCallback(item)
await item.update({ baz: 'baz' })
await d.update({ ref: item })
// NOTE see #1
await delay(5)
expect(spy).toHaveBeenCalledTimes(1)
await item.update({ baz: 'bar' })
// make sure things are updating correctly
expect(vm.d).toEqual({
ref: { baz: 'bar' },
})
// we call update twice to make sure our mock works
expect(spy).toHaveBeenCalledTimes(2)
await d.update({ ref: b })
// NOTE see #1
await delay(5)
it('unbinds removed properties', async () => {
// @ts-ignore
const a: firestore.DocumentReference = db.collection().doc()
const unbindSpy = spyUnbind(a)
const callbackSpy = spyOnSnapshotCallback(a)
const onSnapshotSpy = spyOnSnapshot(a)
// @ts-ignore
const item: firestore.DocumentReference = db.collection().doc()
await a.update({ isA: true })
await b.update({ isB: true })
await item.update({ a })
expect(unbindSpy).toHaveBeenCalledTimes(0)
expect(callbackSpy).toHaveBeenCalledTimes(0)
expect(onSnapshotSpy).toHaveBeenCalledTimes(0)
await bind('item', item)
expect(unbindSpy).toHaveBeenCalledTimes(0)
expect(callbackSpy).toHaveBeenCalledTimes(1)
expect(onSnapshotSpy).toHaveBeenCalledTimes(1)