Skip to content

Commit e132caf

Browse files
committed
test: options api
1 parent c4f1cb6 commit e132caf

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

tests/firestore/document.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ import { mount } from '@vue/test-utils'
22
import { describe, expect, it } from 'vitest'
33
import { useDocument } from '../../src'
44
import {
5-
addDoc,
6-
collection,
7-
doc,
5+
doc as originalDoc,
86
DocumentData,
97
FirestoreError,
108
setDoc,
119
updateDoc,
1210
} from 'firebase/firestore'
1311
import { expectType, setupFirestoreRefs, tds, firestore } from '../utils'
14-
import { usePendingPromises } from '../../src/vuefire/firestore'
1512
import { type Ref } from 'vue'
1613

1714
describe('Firestore documents', () => {
18-
const { itemRef, listRef, orderedListRef } = setupFirestoreRefs()
15+
const { doc } = setupFirestoreRefs()
16+
const itemRef = doc()
1917

2018
it('binds a document', async () => {
2119
const wrapper = mount(
@@ -43,6 +41,7 @@ describe('Firestore documents', () => {
4341

4442
tds(() => {
4543
const db = firestore
44+
const doc = originalDoc
4645
const itemRef = doc(db, 'todos', '1')
4746
expectType<Ref<DocumentData | null>>(useDocument(itemRef))
4847
// @ts-expect-error

tests/firestore/options.spec.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import { type Ref } from 'vue'
99

1010
const component = defineComponent({ template: 'no' })
1111

12-
describe.skip('Firestore: Options API', () => {
13-
const { itemRef, listRef, orderedListRef, collection, doc } =
14-
setupFirestoreRefs()
12+
describe('Firestore: Options API', () => {
13+
const { collection, doc } = setupFirestoreRefs()
1514

1615
it('allows customizing $rtdbBind', () => {
1716
const wrapper = mount(component, {
@@ -50,14 +49,13 @@ describe.skip('Firestore: Options API', () => {
5049
}
5150
)
5251

53-
const items = collection()
54-
await items.add({})
52+
const itemsRef = collection()
53+
await addDoc(itemsRef, {})
5554

56-
await wrapper.vm.$bind('items', items)
55+
await wrapper.vm.$bind('items', itemsRef)
5756

5857
expect(pluginOptions.serialize).toHaveBeenCalledTimes(1)
5958
expect(pluginOptions.serialize).toHaveBeenCalledWith(
60-
// @ts-ignore WTF TS?????
6159
expect.objectContaining({ data: expect.any(Function) })
6260
)
6361
expect(wrapper.vm.items).toEqual([{ foo: 'bar' }])
@@ -79,18 +77,16 @@ describe.skip('Firestore: Options API', () => {
7977
}
8078
)
8179

82-
// @ts-ignore
83-
const items: firestore.CollectionReference = db.collection()
84-
await items.add({})
80+
const itemsRef = collection()
81+
await addDoc(itemsRef, {})
8582

8683
const spy = vi.fn(() => ({ bar: 'bar' }))
8784

88-
await wrapper.vm.$bind('items', items, { serialize: spy })
85+
await wrapper.vm.$bind('items', itemsRef, { serialize: spy })
8986

9087
expect(pluginOptions.serialize).not.toHaveBeenCalled()
9188
expect(spy).toHaveBeenCalledTimes(1)
9289
expect(spy).toHaveBeenCalledWith(
93-
// @ts-ignore WTF TS?????
9490
expect.objectContaining({ data: expect.any(Function) })
9591
)
9692
expect(wrapper.vm.items).toEqual([{ bar: 'bar' }])

tests/utils.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,28 @@ let _id = 0
3636
export function setupFirestoreRefs() {
3737
const testId = _id++
3838
const testsCollection = collection(firestore, `__tests`)
39-
const itemRef = doc(testsCollection, `item:${testId}`)
40-
const forItemsRef = doc(testsCollection, `forItems:${testId}`)
39+
const itemRef = doc(testsCollection)
40+
// let firestore generate the id
41+
const forItemsRef = doc(testsCollection)
4142

4243
const listRef = collection(forItemsRef, 'list')
4344
const orderedListRef = firestoreQuery(listRef, orderBy('name'))
4445

45-
beforeAll(async () => {
46+
afterAll(async () => {
4647
// clean up the tests data
4748
await Promise.all([
4849
deleteDoc(itemRef),
4950
...[...docsToClean].map((doc) => deleteDoc(doc)),
50-
deleteDoc(forItemsRef),
51-
...[...collectionsToClean].map((collection) =>
52-
clearCollection(collection)
53-
),
54-
clearCollection(listRef),
55-
clearCollection(testsCollection),
5651
])
52+
await Promise.all(
53+
[...collectionsToClean].map((collection) => clearCollection(collection))
54+
)
55+
// must be done after the cleanup of its docs
56+
await deleteDoc(forItemsRef),
57+
await Promise.all([
58+
clearCollection(listRef),
59+
clearCollection(testsCollection),
60+
])
5761
})
5862

5963
// for automatically generated collections

0 commit comments

Comments
 (0)