From 574f6918d87125d5ba863a6a2cc24f8a78cf0040 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Tue, 27 Apr 2021 11:02:26 -0500 Subject: [PATCH] fix(database, update): allow empty objects in ref.update() As pointed out by @daveGregorian firebase-js-sdk allows empty objects while the code here was enforcing that the objects had at least one key Fixes #5218 --- packages/database/e2e/reference/update.e2e.js | 18 ++++++++---------- packages/database/lib/DatabaseReference.js | 6 ------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/database/e2e/reference/update.e2e.js b/packages/database/e2e/reference/update.e2e.js index c7fb754843..3dc34639e7 100644 --- a/packages/database/e2e/reference/update.e2e.js +++ b/packages/database/e2e/reference/update.e2e.js @@ -34,16 +34,6 @@ describe('database().ref().update()', function () { } }); - it('throws if values does not contain any values', async function () { - try { - await firebase.database().ref(TEST_PATH).update({}); - return Promise.reject(new Error('Did not throw an Error.')); - } catch (error) { - error.message.should.containEql("'values' must be an object containing multiple values"); - return Promise.resolve(); - } - }); - it('throws if update paths are not valid', async function () { try { await firebase.database().ref(TEST_PATH).update({ @@ -83,6 +73,14 @@ describe('database().ref().update()', function () { foo: value, }), ); + + await ref.update({}); // empty update should pass, but no side effects + const snapshot2 = await ref.once('value'); + snapshot2.val().should.eql( + jet.contextify({ + foo: value, + }), + ); }); it('callback if function is passed', async function () { diff --git a/packages/database/lib/DatabaseReference.js b/packages/database/lib/DatabaseReference.js index 5742e84216..0ebe0119f4 100644 --- a/packages/database/lib/DatabaseReference.js +++ b/packages/database/lib/DatabaseReference.js @@ -112,12 +112,6 @@ export default class DatabaseReference extends DatabaseQuery { throw new Error("firebase.database().ref().update(*) 'values' must be an object."); } - if (!Object.keys(values).length) { - throw new Error( - "firebase.database().ref().update(*) 'values' must be an object containing multiple values.", - ); - } - const keys = Object.keys(values); for (let i = 0; i < keys.length; i++) { if (!isValidPath(keys[i])) {