Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(firestore): support waitForPendingWrites() API #4176

Merged
merged 10 commits into from
Aug 30, 2020
38 changes: 38 additions & 0 deletions packages/firestore/e2e/firestore.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,42 @@ describe('firestore()', () => {
}
});
});

describe('wait for pending writes', () => {
it('waits for pending writes', async () => {

const waitForPromiseMs = 500;
const testTimeoutMs = 10000;

await firebase.firestore().disableNetwork();

//set up a pending write

const db = firebase.firestore();
const id = 'foobar';
const ref = db.doc(`v6/${id}`);
ref.set({ foo: 'bar' });

//waitForPendingWrites should never resolve, but unfortunately we can only
//test that this is not returning within X ms
mikehardy marked this conversation as resolved.
Show resolved Hide resolved

const timedOutWithNetworkDisabled = await Promise.race([
firebase.firestore().waitForPendingWrites().then(() => false),
new Promise(resolve => setTimeout(resolve, waitForPromiseMs)).then(() => true)
]);

should(timedOutWithNetworkDisabled).equal(true);

await firebase.firestore().enableNetwork();

const timedOutWithNetworkEnabled = await Promise.race([
firebase.firestore().waitForPendingWrites().then(() => false),
new Promise(resolve => setTimeout(resolve, testTimeoutMs)).then(() => true)
]);

should(timedOutWithNetworkEnabled).equal(false);

});
});

});