How to use the @posva/vuefire-test-helpers.spyUnbind function in @posva/vuefire-test-helpers

To help you get started, we’ve selected a few @posva/vuefire-test-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / document.spec.ts View on Github external
it('manually unbinds a document', async () => {
    document = collection.doc()
    await document.update({ foo: 'foo' })
    const unbindSpy = spyUnbind(document)
    let unbind: () => void = () => {
      throw new Error('Promise was not called')
    }
    await new Promise((resolve, reject) => {
      unbind = bindDocument({ vm, document, key: 'item', resolve, reject, ops })
    })

    expect(unbindSpy).not.toHaveBeenCalled()
    expect(vm.item).toEqual({ foo: 'foo' })
    unbind()
    expect(unbindSpy).toHaveBeenCalled()

    // reset data manually
    vm.item = null
    await document.update({ foo: 'foo' })
    expect(vm.item).toEqual(null)
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-collections.spec.ts View on Github external
it('unbinds refs when the collection is unbound', async () => {
    const items = db.collection()
    const spyA = spyUnbind(a)
    const spyB = spyUnbind(b)
    await items.add({ ref: a })
    await items.add({ ref: b })
    // @ts-ignore
    await bind('items', items)

    expect(spyA).toHaveBeenCalledTimes(0)
    expect(spyB).toHaveBeenCalledTimes(0)

    unbind()

    expect(spyA).toHaveBeenCalledTimes(1)
    expect(spyB).toHaveBeenCalledTimes(1)

    spyA.mockRestore()
    spyB.mockRestore()
  })
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-documents.spec.ts View on Github external
it('unbinds when a ref is replaced', async () => {
    const aSpy = spyUnbind(a)
    const cSpy = spyUnbind(c)
    const dSpy = spyUnbind(d)

    await bind('d', d)
    expect(vm.d).toEqual({
      ref: {
        isC: true,
      },
    })

    await d.update({ ref: a })
    // NOTE see #1
    await delay(5)
    expect(vm.d).toEqual({
      ref: {
        isA: true,
      },
    })
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-documents.spec.ts View on Github external
it('unbinds when a ref is replaced', async () => {
    const aSpy = spyUnbind(a)
    const cSpy = spyUnbind(c)
    const dSpy = spyUnbind(d)

    await bind('d', d)
    expect(vm.d).toEqual({
      ref: {
        isC: true,
      },
    })

    await d.update({ ref: a })
    // NOTE see #1
    await delay(5)
    expect(vm.d).toEqual({
      ref: {
        isA: true,
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-documents.spec.ts View on Github external
it('unbinds all refs when the document is unbound', async () => {
    const cSpy = spyUnbind(c)
    const dSpy = spyUnbind(d)
    // rebind to use the spies
    await bind('d', d)
    expect(vm.d).toEqual({
      ref: {
        isC: true,
      },
    })
    unbind()

    expect(dSpy).toHaveBeenCalledTimes(1)
    expect(cSpy).toHaveBeenCalledTimes(1)

    cSpy.mockRestore()
    dSpy.mockRestore()
  })
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-documents.spec.ts View on Github external
it('unbinds when a ref is replaced', async () => {
    const aSpy = spyUnbind(a)
    const cSpy = spyUnbind(c)
    const dSpy = spyUnbind(d)

    await bind('d', d)
    expect(vm.d).toEqual({
      ref: {
        isC: true,
      },
    })

    await d.update({ ref: a })
    // NOTE see #1
    await delay(5)
    expect(vm.d).toEqual({
      ref: {
        isA: true,
      },
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / collection.spec.ts View on Github external
it('manually unbinds a collection', async () => {
    // @ts-ignore
    collection = db.collection()
    await collection.add({ text: 'foo' })
    const unbindSpy = spyUnbind(collection)
    let unbind: () => void = () => {
      throw new Error('Promise was not called')
    }
    await new Promise((resolve, reject) => {
      unbind = bindCollection({
        vm,
        collection,
        key: 'items',
        resolve,
        reject,
        ops,
      })
    })

    expect(unbindSpy).not.toHaveBeenCalled()
    expect(vm.items).toEqual([{ text: 'foo' }])
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-collections.spec.ts View on Github external
it('unbinds nested refs when the collection is unbound', async () => {
    const items = db.collection()
    const spyA = spyUnbind(a)
    await items.add({ ref: { ref: a } })
    // @ts-ignore
    await bind('items', items)

    expect(spyA).toHaveBeenCalledTimes(0)

    unbind()
    expect(spyA).toHaveBeenCalledTimes(1)

    spyA.mockRestore()
  })
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-documents.spec.ts View on Github external
it('unbinds multiple refs when the document is unbound', async () => {
    const aSpy = spyUnbind(a)
    const cSpy = spyUnbind(c)
    const dSpy = spyUnbind(item)

    await item.update({ c, a })

    await bind('item', item)
    unbind()

    expect(dSpy).toHaveBeenCalledTimes(1)
    expect(cSpy).toHaveBeenCalledTimes(1)
    expect(aSpy).toHaveBeenCalledTimes(1)

    aSpy.mockRestore()
    cSpy.mockRestore()
    dSpy.mockRestore()
  })
github vuejs / vuefire / packages / @posva / vuefire-core / __tests__ / firestore / refs-documents.spec.ts View on Github external
it('unbinds nested refs when the document is unbound', async () => {
    const aSpy = spyUnbind(a)
    const cSpy = spyUnbind(b)
    const dSpy = spyUnbind(item)

    await b.update({ ref: a })
    await item.update({ ref: b })

    await bind('item', item)
    unbind()

    expect(dSpy).toHaveBeenCalledTimes(1)
    expect(cSpy).toHaveBeenCalledTimes(1)
    expect(aSpy).toHaveBeenCalledTimes(1)

    aSpy.mockRestore()
    cSpy.mockRestore()
    dSpy.mockRestore()
  })