-
Notifications
You must be signed in to change notification settings - Fork 306
/
Copy pathuseDocument.test.ts
40 lines (31 loc) · 1.01 KB
/
useDocument.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { addDoc, collection, doc } from 'firebase/firestore';
import { db } from '../test/firebase';
import { renderHook } from '@testing-library/react-hooks';
import { useDocument } from './useDocument';
describe('useDocument hook', () => {
test('begins in loading state', async () => {
// arrange
const { id } = await addDoc(collection(db, 'test'), {});
// act
const { result, unmount } = renderHook(() =>
useDocument(doc(collection(db, 'test'), id))
);
//assert
expect(result.current[1]).toBeTruthy();
// clean up
unmount();
});
test('loads and returns data from server', async () => {
// arrange
const { id } = await addDoc(collection(db, 'test'), { name: 'bo' });
// act
const { result, waitFor, unmount } = renderHook(() =>
useDocument(doc(collection(db, 'test'), id))
);
await waitFor(() => result.current[1] === false);
// assert
expect(result.current[0]?.data()).toEqual({ name: 'bo' });
// clean up
unmount();
});
});