-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathapp.test.ts
More file actions
141 lines (124 loc) · 4.13 KB
/
app.test.ts
File metadata and controls
141 lines (124 loc) · 4.13 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { describe, expect, it, jest } from '@jest/globals';
import { checkV9Deprecation } from '../lib/common/unitTestUtils';
import firebase, {
deleteApp,
registerVersion,
onLog,
getApps,
initializeApp,
getApp,
setLogLevel,
} from '../lib';
import { Logger } from '../lib/internal/logger';
import { NativeFirebaseError } from '../lib/internal';
describe('App', function () {
describe('modular', function () {
it('`deleteApp` function is properly exposed to end user', function () {
expect(deleteApp).toBeDefined();
});
it('`registerVersion` function is properly exposed to end user', function () {
expect(registerVersion).toBeDefined();
});
it('`onLog` function is properly exposed to end user', function () {
expect(onLog).toBeDefined();
});
it('`getApps` function is properly exposed to end user', function () {
expect(getApps).toBeDefined();
});
it('`initializeApp` function is properly exposed to end user', function () {
expect(initializeApp).toBeDefined();
});
it('`getApp` function is properly exposed to end user', function () {
expect(getApp).toBeDefined();
});
it('`setLogLevel` function is properly exposed to end user', function () {
expect(setLogLevel).toBeDefined();
});
it('`onLog()` is called when using Logger (currently only VertexAI uses `onLog()`)', function () {
const logger = new Logger('@firebase/vertexai');
const spy2 = jest.fn();
// eat the log messages that actually go through so we don't pollute test logs
// eslint-disable-next-line no-console
const origInfo = console.info;
// eslint-disable-next-line no-console
console.info = (_: string) => {};
try {
onLog(spy2);
logger.info('test');
expect(spy2).toHaveBeenCalledWith(
expect.objectContaining({
args: ['test'],
level: 'info',
message: 'test',
type: '@firebase/vertexai',
}),
);
} finally {
// eslint-disable-next-line no-console
console.info = origInfo;
}
});
});
describe('`console.warn` only called for non-modular API', function () {
it('deleteApp', function () {
// this test has a slightly special setup
// @ts-ignore test
jest.spyOn(getApp(), '_deleteApp').mockImplementation(() => Promise.resolve(null));
checkV9Deprecation(
() => {}, // no modular replacement
() => getApp().delete(), // modular getApp(), then non-modular to check
);
});
it('getApps', function () {
checkV9Deprecation(
() => getApps(),
() => firebase.apps,
);
});
it('getApp', function () {
checkV9Deprecation(
() => getApp(),
() => firebase.app(),
);
});
it('setLogLevel', function () {
checkV9Deprecation(
() => setLogLevel('debug'),
() => firebase.setLogLevel('debug'),
);
});
it('FirebaseApp.toString()', function () {
checkV9Deprecation(
() => {}, // no modular replacement
() => getApp().toString(), // modular getApp(), then non-modular to check
);
});
it('FirebaseApp.extendApp()', function () {
checkV9Deprecation(
// no modular replacement for this one so no modular func to send in
() => {},
// modular getApp(), then non-modular to check
() => {
const app = getApp();
(app as any).extendApp({ some: 'property' });
return;
},
);
});
});
describe('`NativeFirebaseError` can cope with missing properties', function () {
it('missing `userInfo.code` does not error', function () {
const testNativeError = {
userInfo: undefined,
};
const testNativeFirebaseError = new NativeFirebaseError(
// @ts-ignore - using malformed object to test handling of malformed objects
testNativeError,
new Error().stack!,
'testNamespace',
);
expect(testNativeFirebaseError.namespace).toBe('testNamespace');
expect(testNativeFirebaseError.code).toBe('testNamespace/unknown');
});
});
});