Skip to content

Commit a0eff21

Browse files
committed
test(database): once option
1 parent 0c321fb commit a0eff21

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tests/database/list.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ describe('Database lists', () => {
5757
expect(wrapper.vm.list).toEqual([])
5858
})
5959

60+
it('fetches once', async () => {
61+
const listRef = databaseRef()
62+
await push(listRef, { name: 'a' })
63+
await push(listRef, { name: 'b' })
64+
65+
const { wrapper, promise } = factory({
66+
ref: listRef,
67+
options: { once: true },
68+
})
69+
70+
await promise.value
71+
expect(wrapper.vm.list).toHaveLength(2)
72+
73+
await push(listRef, { name: 'c' })
74+
expect(wrapper.vm.list).toHaveLength(2)
75+
})
76+
6077
it('add items to the list', async () => {
6178
const { wrapper, data, listRef } = factory()
6279

tests/database/objects.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ describe('Database objects', () => {
6666
expect(wrapper.vm.item).toEqual(undefined)
6767
})
6868

69+
it('fetches once', async () => {
70+
const itemRef = databaseRef()
71+
await set(itemRef, { name: 'a' })
72+
const { wrapper, promise } = factory({
73+
ref: itemRef,
74+
options: { once: true },
75+
})
76+
77+
await promise.value
78+
79+
expect(wrapper.vm.item).toEqual({ name: 'a' })
80+
81+
await set(itemRef, { name: 'b' })
82+
expect(wrapper.vm.item).toEqual({ name: 'a' })
83+
})
84+
6985
it('can be bound to a Vue ref', async () => {
7086
const aRef = databaseRef()
7187
const bRef = databaseRef()

0 commit comments

Comments
 (0)