Skip to content

Commit 4bc8ad5

Browse files
committed
test: when a promise is resolved, data is available
1 parent ecb3ae4 commit 4bc8ad5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

test/bind.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ test('returs a promise', () => {
4848
expect(vm.$bind('item', document) instanceof Promise).toBe(true)
4949
})
5050

51+
test('waits for the data to be set when binding a collection', async () => {
52+
collection.add({ foo: 'foo' })
53+
const promise = vm.$bind('items', collection)
54+
expect(vm.items).toEqual([])
55+
await promise
56+
expect(vm.items).toEqual([{ foo: 'foo' }])
57+
})
58+
59+
test('waits for the data to be set when binding a document', async () => {
60+
document.update({ foo: 'foo' })
61+
const promise = vm.$bind('item', document)
62+
expect(vm.item).toEqual(null)
63+
await promise
64+
expect(vm.item).toEqual({ foo: 'foo' })
65+
})
66+
5167
test('rejects the promise when errors', async () => {
5268
const fakeOnSnapshot = (_, fail) => {
5369
fail(new Error('nope'))

test/refs.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('is null if ref does not exist', async () => {
8585
})
8686
})
8787

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

9191
// Mock c onSnapshot to spy when the callback is called

0 commit comments

Comments
 (0)