Skip to content

Commit 7bc5c93

Browse files
committed
Add a unit test for calling clearPersistence() on a newly-created Firestore instance.
1 parent 04d4f97 commit 7bc5c93

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/firestore/test/integration/api/database.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ apiDescribe('Database', (persistence: boolean) => {
10741074

10751075
// eslint-disable-next-line no-restricted-properties
10761076
(persistence ? it : it.skip)(
1077-
'can clear persistence if the client has not been initialized',
1077+
'can clear persistence if the client has been terminated',
10781078
async () => {
10791079
await withTestDoc(persistence, async docRef => {
10801080
const firestore = docRef.firestore;
@@ -1096,6 +1096,30 @@ apiDescribe('Database', (persistence: boolean) => {
10961096
}
10971097
);
10981098

1099+
// eslint-disable-next-line no-restricted-properties
1100+
(persistence ? it : it.skip)(
1101+
'can clear persistence if the client has not been initialized',
1102+
async () => {
1103+
await withTestDoc(persistence, async docRef => {
1104+
const firestore = docRef.firestore;
1105+
await docRef.set({ foo: 'bar' });
1106+
const app = docRef.firestore.app;
1107+
const name = app.name;
1108+
const options = app.options;
1109+
1110+
await app.delete();
1111+
const app2 = firebase.initializeApp(options, name);
1112+
const firestore2 = firebase.firestore!(app2);
1113+
await firestore2.clearPersistence();
1114+
await firestore2.enablePersistence();
1115+
const docRef2 = firestore2.doc(docRef.path);
1116+
await expect(
1117+
docRef2.get({ source: 'cache' })
1118+
).to.eventually.be.rejectedWith('Failed to get document from cache.');
1119+
});
1120+
}
1121+
);
1122+
10991123
// eslint-disable-next-line no-restricted-properties
11001124
(persistence ? it : it.skip)(
11011125
'cannot clear persistence if the client has been initialized',

0 commit comments

Comments
 (0)