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 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)
it('does not rebind if it is the same ref', async () => {
const spy = spyOnSnapshot(item)
await item.update({ baz: 'baz' })
await d.update({ ref: item })
// NOTE see #1
await delay(5)
expect(spy).toHaveBeenCalledTimes(1)
await d.update({ ref: item })
await delay(5)
expect(spy).toHaveBeenCalledTimes(1)
spy.mockRestore()
})