Skip to content

Commit 574f691

Browse files
committed
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
1 parent a51e97b commit 574f691

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

packages/database/e2e/reference/update.e2e.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ describe('database().ref().update()', function () {
3434
}
3535
});
3636

37-
it('throws if values does not contain any values', async function () {
38-
try {
39-
await firebase.database().ref(TEST_PATH).update({});
40-
return Promise.reject(new Error('Did not throw an Error.'));
41-
} catch (error) {
42-
error.message.should.containEql("'values' must be an object containing multiple values");
43-
return Promise.resolve();
44-
}
45-
});
46-
4737
it('throws if update paths are not valid', async function () {
4838
try {
4939
await firebase.database().ref(TEST_PATH).update({
@@ -83,6 +73,14 @@ describe('database().ref().update()', function () {
8373
foo: value,
8474
}),
8575
);
76+
77+
await ref.update({}); // empty update should pass, but no side effects
78+
const snapshot2 = await ref.once('value');
79+
snapshot2.val().should.eql(
80+
jet.contextify({
81+
foo: value,
82+
}),
83+
);
8684
});
8785

8886
it('callback if function is passed', async function () {

packages/database/lib/DatabaseReference.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ export default class DatabaseReference extends DatabaseQuery {
112112
throw new Error("firebase.database().ref().update(*) 'values' must be an object.");
113113
}
114114

115-
if (!Object.keys(values).length) {
116-
throw new Error(
117-
"firebase.database().ref().update(*) 'values' must be an object containing multiple values.",
118-
);
119-
}
120-
121115
const keys = Object.keys(values);
122116
for (let i = 0; i < keys.length; i++) {
123117
if (!isValidPath(keys[i])) {

0 commit comments

Comments
 (0)