Skip to content

Commit 4db21d7

Browse files
authored
Merge pull request soumak77#111 from bookcreator/slashes
Fix for soumak77#110
2 parents b683ee4 + f09bf69 commit 4db21d7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/firebase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ MockFirebase.prototype.update = function (changes, callback) {
194194
// operate as a multi-set
195195
_.keys(changes).forEach(function (key) {
196196
var val = changes[key];
197-
_.set(data, key.replace(/\//g, '.'), _.isObject(val) ? utils.updateToRtdbObject(val) : val);
197+
_.set(data, key.replace(/^\//, '').replace(/\//g, '.'), _.isObject(val) ? utils.updateToRtdbObject(val) : val);
198198
});
199199
data = utils.removeEmptyRtdbProperties(data);
200200
self._dataChanged(data);

test/unit/firebase.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,15 @@ describe('MockFirebase', function () {
546546
expect(ref.getData().some).to.eql({prop: 12});
547547
});
548548

549+
it('can work with nested paths beginning with /', function () {
550+
var update = {};
551+
update['some/prop/withoutSlash'] = 12;
552+
update['/some/prop/withSlash'] = 12;
553+
ref.update(update);
554+
ref.flush();
555+
expect(ref.getData().some.prop).to.eql({withoutSlash: 12, withSlash: 12});
556+
});
557+
549558
it('overrides the paths with existing data', function () {
550559
ref.child('some').child('prop').set({foo: 1});
551560
ref.flush();

0 commit comments

Comments
 (0)