Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(useFirestore): support reactive query (#2008)
- Loading branch information
Showing
3 changed files
with
63 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ref } from 'vue-demi' | ||
import { onSnapshot } from 'firebase/firestore' | ||
import type { Mock } from 'vitest' | ||
import { useFirestore } from './index' | ||
|
||
vi.mock('firebase/firestore', () => ({ | ||
onSnapshot: vi.fn(), | ||
})) | ||
|
||
describe('useFirestore', () => { | ||
beforeEach(() => { | ||
(onSnapshot as Mock).mockClear() | ||
}) | ||
|
||
it('should call onSnapshot with document reference', () => { | ||
const docRef = { path: 'users' } as any | ||
useFirestore(docRef) | ||
expect((onSnapshot as Mock).mock.calls[0][0]).toStrictEqual(docRef) | ||
}) | ||
|
||
it('should call onSnapshot with ref value of document reference', () => { | ||
const docRef = { path: 'posts' } as any | ||
const refOfDocRef = ref(docRef) | ||
useFirestore(refOfDocRef) | ||
expect((onSnapshot as Mock).mock.calls[0][0]).toStrictEqual(docRef) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters