Skip to content

Commit 373b1e3

Browse files
committed
add a bunch of todo tests
1 parent 87ef250 commit 373b1e3

File tree

5 files changed

+185
-75
lines changed

5 files changed

+185
-75
lines changed

reactfire/components.test.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { of, Subject, Observable, observable } from 'rxjs';
2+
import { render, waitForElement, cleanup } from '@testing-library/react';
3+
import * as React from 'react';
4+
import 'jest-dom/extend-expect';
5+
6+
const mockTrace = {
7+
start: jest.fn(),
8+
stop: jest.fn()
9+
};
10+
11+
const mockPerf = {
12+
trace: jest.fn(() => mockTrace)
13+
};
14+
15+
const mockFirebase = {
16+
performance: jest.fn(() => mockPerf)
17+
};
18+
19+
describe('SuspenseWithPerf', () => {
20+
afterEach(cleanup);
21+
22+
test.todo(
23+
'renders the same as Suspense (fallback until children stop throwing a promise)'
24+
);
25+
26+
test.todo('creates a trace with the correct name');
27+
28+
test.todo('starts a trace when it first renders');
29+
30+
test.todo('stops the trace when it renders children');
31+
32+
test.todo('can find fireperf from Context');
33+
34+
test.todo('can use firePerf from props');
35+
});
36+
37+
describe('AuthCheck', () => {
38+
afterEach(cleanup);
39+
40+
test.todo('can find firebase Auth from Context');
41+
42+
test.todo('can use firebase Auth from props');
43+
44+
test.todo('renders the fallback if a user is not signed in');
45+
46+
test.todo('renders children if a user is logged in');
47+
48+
test.todo('checks requiredClaims');
49+
});

reactfire/firebaseContext.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { renderHook, act } from '@testing-library/react-hooks';
2+
import * as React from 'react';
3+
import 'jest-dom/extend-expect';
4+
5+
describe('FirebaseAppProvider', () => {
6+
test.todo('calls firebase.initializeApp');
7+
8+
test.todo('initializes fireperf if specified');
9+
});
10+
11+
describe('useFirebaseApp', () => {
12+
test.todo('finds firebase from Context');
13+
14+
test.todo('throws an error if Firebase is not in context');
15+
});

reactfire/index.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { renderHook, act } from '@testing-library/react-hooks';
2+
import * as React from 'react';
3+
import 'jest-dom/extend-expect';
4+
5+
describe('useUser', () => {
6+
test.todo('can find firebase.auth() from Context');
7+
8+
test.todo('throws an error if firebase.auth() is not available');
9+
10+
test.todo('returns the same value as firebase.auth().currentUser()');
11+
});
12+
13+
describe('Firestore', () => {
14+
describe('useFirestoreDoc', () => {
15+
test.todo('returns the same value as ref.onSnapshot()');
16+
});
17+
18+
describe('useFirestoreCollection', () => {
19+
test.todo('returns the same value as ref.onSnapshot()');
20+
});
21+
});
22+
23+
describe('Realtime Database (RTDB)', () => {
24+
describe('useDatabaseObject', () => {
25+
test.todo("returns the same value as ref.on('value')");
26+
});
27+
28+
describe('useDatabaseList', () => {
29+
test.todo("returns the same value as ref.on('value')");
30+
});
31+
});
32+
33+
describe('Storage', () => {
34+
describe('useStorageTask', () => {
35+
test.todo('returns the same value as uploadTask');
36+
});
37+
38+
describe('useStorageDownloadURL', () => {
39+
test.todo('returns the same value as getDownloadURL');
40+
});
41+
});

reactfire/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"types": "index.d.ts",
77
"scripts": {
88
"build-dev": "tsc",
9+
"test-dev": "jest --verbose --watch",
910
"test": "jest",
1011
"watch": "tsc index.ts --lib DOM,ES2018 --watch --sourceMap --declaration --jsx react",
1112
"docs": "./node_modules/.bin/typedoc --mode modules --json docs/reactfire-metadata.json index.ts && node ./docs/generate-readme.js",

reactfire/util/use-observable.test.tsx

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,94 +7,98 @@ import { ReactFireOptions } from '..';
77
import * as React from 'react';
88
import 'jest-dom/extend-expect';
99

10-
afterEach(cleanup);
10+
describe('useObservable', () => {
11+
afterEach(cleanup);
1112

12-
it('throws a promise if the observable has no initial value', () => {
13-
const observable$: Subject<any> = new Subject();
13+
it('throws a promise if the observable has no initial value', () => {
14+
const observable$: Subject<any> = new Subject();
1415

15-
try {
16-
useObservable(observable$, 'test');
17-
} catch (thingThatWasThrown) {
18-
expect(thingThatWasThrown).toBeInstanceOf(Promise);
19-
}
20-
});
16+
try {
17+
useObservable(observable$, 'test');
18+
} catch (thingThatWasThrown) {
19+
expect(thingThatWasThrown).toBeInstanceOf(Promise);
20+
}
21+
});
2122

22-
it('can return a startval and then the observable once it is ready', () => {
23-
const startVal = 'howdy';
24-
const observableVal = "y'all";
25-
const observable$: Subject<any> = new Subject();
23+
it('can return a startval and then the observable once it is ready', () => {
24+
const startVal = 'howdy';
25+
const observableVal = "y'all";
26+
const observable$: Subject<any> = new Subject();
2627

27-
const { result, waitForNextUpdate } = renderHook(() =>
28-
useObservable(observable$, 'test', startVal)
29-
);
28+
const { result, waitForNextUpdate } = renderHook(() =>
29+
useObservable(observable$, 'test', startVal)
30+
);
3031

31-
expect(result.current).toEqual(startVal);
32+
expect(result.current).toEqual(startVal);
3233

33-
// prove that it actually does emit the value from the observable too
34-
act(() => observable$.next(observableVal));
35-
expect(result.current).toEqual(observableVal);
36-
});
34+
// prove that it actually does emit the value from the observable too
35+
act(() => observable$.next(observableVal));
36+
expect(result.current).toEqual(observableVal);
37+
});
3738

38-
it('ignores provided initial value if the observable is ready right away', () => {
39-
const startVal = 'howdy';
40-
const observableVal = "y'all";
41-
const observable$ = of(observableVal);
39+
it('ignores provided initial value if the observable is ready right away', () => {
40+
const startVal = 'howdy';
41+
const observableVal = "y'all";
42+
const observable$ = of(observableVal);
4243

43-
const { result, waitForNextUpdate } = renderHook(() =>
44-
useObservable(observable$, 'test', startVal)
45-
);
44+
const { result, waitForNextUpdate } = renderHook(() =>
45+
useObservable(observable$, 'test', startVal)
46+
);
4647

47-
expect(result.current).toEqual(observableVal);
48-
});
48+
expect(result.current).toEqual(observableVal);
49+
});
4950

50-
it('works with Suspense', async () => {
51-
const observableFinalVal = "y'all";
52-
const observable$ = new Subject();
53-
const actualComponentId = 'actual-component';
54-
const fallbackComponentId = 'fallback-component';
55-
56-
const FallbackComponent = () => (
57-
<h1 data-testid={fallbackComponentId}>Fallback</h1>
58-
);
59-
60-
const Component = () => {
61-
const val = useObservable(observable$, 'test-suspense');
62-
return <h1 data-testid={actualComponentId}>{val}}</h1>;
63-
};
64-
65-
const { queryByTestId, getByTestId } = render(
66-
<React.Suspense fallback={<FallbackComponent />}>
67-
<Component />
68-
</React.Suspense>
69-
);
70-
71-
// make sure Suspense renders the fallback component if the observable has not emitted a value
72-
expect(getByTestId(fallbackComponentId)).toBeInTheDocument();
73-
expect(queryByTestId(actualComponentId)).toBeNull();
74-
75-
act(() => observable$.next(observableFinalVal));
76-
await waitForElement(() => getByTestId(actualComponentId));
77-
78-
// make sure Suspense correctly renders its child after the observable emits a value
79-
expect(getByTestId(actualComponentId)).toBeInTheDocument();
80-
expect(getByTestId(actualComponentId)).toHaveTextContent(observableFinalVal);
81-
expect(queryByTestId(fallbackComponentId)).toBeNull();
82-
});
51+
it('works with Suspense', async () => {
52+
const observableFinalVal = "y'all";
53+
const observable$ = new Subject();
54+
const actualComponentId = 'actual-component';
55+
const fallbackComponentId = 'fallback-component';
56+
57+
const FallbackComponent = () => (
58+
<h1 data-testid={fallbackComponentId}>Fallback</h1>
59+
);
60+
61+
const Component = () => {
62+
const val = useObservable(observable$, 'test-suspense');
63+
return <h1 data-testid={actualComponentId}>{val}}</h1>;
64+
};
65+
66+
const { queryByTestId, getByTestId } = render(
67+
<React.Suspense fallback={<FallbackComponent />}>
68+
<Component />
69+
</React.Suspense>
70+
);
71+
72+
// make sure Suspense renders the fallback component if the observable has not emitted a value
73+
expect(getByTestId(fallbackComponentId)).toBeInTheDocument();
74+
expect(queryByTestId(actualComponentId)).toBeNull();
75+
76+
act(() => observable$.next(observableFinalVal));
77+
await waitForElement(() => getByTestId(actualComponentId));
78+
79+
// make sure Suspense correctly renders its child after the observable emits a value
80+
expect(getByTestId(actualComponentId)).toBeInTheDocument();
81+
expect(getByTestId(actualComponentId)).toHaveTextContent(
82+
observableFinalVal
83+
);
84+
expect(queryByTestId(fallbackComponentId)).toBeNull();
85+
});
8386

84-
it('emits new values as the observable changes', async () => {
85-
const startVal = 'start';
86-
const values = ['a', 'b', 'c'];
87-
const observableSecondValue = 'b';
88-
const observable$ = new Subject();
87+
it('emits new values as the observable changes', async () => {
88+
const startVal = 'start';
89+
const values = ['a', 'b', 'c'];
90+
const observableSecondValue = 'b';
91+
const observable$ = new Subject();
8992

90-
const { result } = renderHook(() =>
91-
useObservable(observable$, 'test', startVal)
92-
);
93+
const { result } = renderHook(() =>
94+
useObservable(observable$, 'test', startVal)
95+
);
9396

94-
expect(result.current).toEqual(startVal);
97+
expect(result.current).toEqual(startVal);
9598

96-
values.forEach(value => {
97-
act(() => observable$.next(value));
98-
expect(result.current).toEqual(value);
99+
values.forEach(value => {
100+
act(() => observable$.next(value));
101+
expect(result.current).toEqual(value);
102+
});
99103
});
100104
});

0 commit comments

Comments
 (0)