Skip to content

Commit 5f22a4e

Browse files
Update tests
1 parent 7a21dca commit 5f22a4e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/firestore/lite/src/api/components.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { newSerializer } from '../../../src/platform/serializer';
2121
import { Firestore } from './database';
2222
import { DatabaseInfo } from '../../../src/core/database_info';
2323
import { logDebug } from '../../../src/util/log';
24+
import { Code, FirestoreError } from '../../../src/util/error';
2425

2526
export const LOG_TAG = 'ComponentProvider';
2627

@@ -44,6 +45,12 @@ const datastoreInstances = new Map<Firestore, Promise<Datastore>>();
4445
* instance is terminated.
4546
*/
4647
export function getDatastore(firestore: Firestore): Promise<Datastore> {
48+
if (firestore._terminated) {
49+
throw new FirestoreError(
50+
Code.FAILED_PRECONDITION,
51+
'The client has already been terminated.'
52+
);
53+
}
4754
if (!datastoreInstances.has(firestore)) {
4855
logDebug(LOG_TAG, 'Initializing Datastore');
4956
const settings = firestore._getSettings();

packages/firestore/lite/test/integration.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ describe('Firestore', () => {
109109
{ apiKey: 'fake-api-key', projectId: 'test-project' },
110110
'test-app-initializeFirestore-twice'
111111
);
112-
initializeFirestore(app, { host: 'localhost', ssl: false });
112+
const db = initializeFirestore(app, {});
113+
114+
// Start the client.
115+
writeBatch(db);
116+
113117
expect(() => {
114-
initializeFirestore(app, { host: 'localhost', ssl: false });
118+
initializeFirestore(app, {});
115119
}).to.throw(
116120
'Firestore has already been started and its settings can no longer be changed.'
117121
);
@@ -132,9 +136,13 @@ describe('Firestore', () => {
132136
// eslint-disable-next-line @typescript-eslint/no-floating-promises
133137
terminate(firestore);
134138

135-
return expect(
136-
getDoc(doc(firestore, 'coll/doc'))
137-
).to.be.eventually.rejectedWith('The client has already been terminated.');
139+
try {
140+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
141+
getDoc(doc(firestore, 'coll/doc'));
142+
expect.fail();
143+
} catch (e) {
144+
expect(e.message).to.equal('The client has already been terminated.');
145+
}
138146
});
139147

140148
it('can call terminate() multiple times', () => {

0 commit comments

Comments
 (0)