Skip to content

Commit

Permalink
test: when a promise is resolved, data is available
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 11, 2017
1 parent ecb3ae4 commit 4bc8ad5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions test/bind.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ test('returs a promise', () => {
expect(vm.$bind('item', document) instanceof Promise).toBe(true)
})

test('waits for the data to be set when binding a collection', async () => {
collection.add({ foo: 'foo' })
const promise = vm.$bind('items', collection)
expect(vm.items).toEqual([])
await promise
expect(vm.items).toEqual([{ foo: 'foo' }])
})

test('waits for the data to be set when binding a document', async () => {
document.update({ foo: 'foo' })
const promise = vm.$bind('item', document)
expect(vm.item).toEqual(null)
await promise
expect(vm.item).toEqual({ foo: 'foo' })
})

test('rejects the promise when errors', async () => {
const fakeOnSnapshot = (_, fail) => {
fail(new Error('nope'))
Expand Down
2 changes: 1 addition & 1 deletion test/refs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test('is null if ref does not exist', async () => {
})
})

test('unbinds previously bound document', async () => {
test('unbinds previously bound document when overwriting a bound', async () => {
const c = collection.doc()

// Mock c onSnapshot to spy when the callback is called
Expand Down

0 comments on commit 4bc8ad5

Please sign in to comment.