-
Notifications
You must be signed in to change notification settings - Fork 204
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
Align DataSnapshot methods to @firebase/database DataSnapshot #926
Conversation
9ec3562
to
ec514e2
Compare
|
||
// Null values are still reported as null. | ||
populate({ myKey: null }); | ||
expect(subject.val()).to.deep.equal({ myKey: null }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed this test case as its incorrect compared to the Firebase SDK, the correct version is now in should deal with null-values appropriately
.
if (numKeys === 0) { | ||
// Empty node | ||
return null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simulates the previously mentioned this.isEmpty()
check the Firebase SDK does.
describe('#hasChildren()', () => { | ||
it('should true for objects', () => { | ||
populate({ | ||
a: 'b', | ||
c: 'd', | ||
nullChild: null, | ||
emptyObjectChild: {}, | ||
emptyArrayChild: [], | ||
}); | ||
expect(subject.hasChildren()).to.be.true; | ||
}); | ||
|
||
it('should be false for non-objects', () => { | ||
populate(23); | ||
expect(subject.hasChildren()).to.be.false; | ||
|
||
populate({ | ||
nullChild: null, | ||
emptyObjectChild: {}, | ||
emptyArrayChild: [], | ||
}); | ||
expect(subject.hasChildren()).to.be.false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.hasChildren()
had no tests so added some by mirroring the .numChildren()
tests above.
3dde778
to
fae1bf0
Compare
fae1bf0
to
f08be25
Compare
Let me get back to you. We got rid of the v1 directory temporarily to unbreak the emulator and people depending on undocumented behavior. We want to move everything back ASAP by releasing a breaking change. That breaking change might actually be the best time to accept your change since it's a good change but changes behavior notably. |
Any update on this @inlined ? |
Bump @inlined |
Haven't forgotten about you. We just haven't made a breaking change yet. Your PR is actually listed on an internal checklist for changes to be made before our next breaking change. |
Thanks (and sorry for the pestering then)! Shall I rebase (/keep rebasing) or wait till you guys are ready and give me a bump? |
I don't want to waste your time chasing after a moving target. I'll reach out or rebase myself. |
Closing this since the changes have been ported to the |
[gh pr checkout 926] |
Description
I've noticed[1] a difference between
DataSnapshot
s methods in this SDK compared to the one used when fetching data (when using the admin SDK).When setting values that are (or contain) empty object/arrays and null values using the admin SDK, when fetching these values back, they're always
null
when calling.val()
.However when creating a
DataSnapshot
with these values and calling.val()
the results don't match.I'm only raising this as an issue because when the functions are being called, I'd expect the
DataSnapshot
provided to the function handler to match theDataSnapshot
when fetched from the same location - currently this isn't the case.Code sample
Using the following data:
{ child: 'foo', nullChild: null, emptyChild: {}, emptyArray: [], child: { nullVal: null, key: 'bar' } }
Setting and then getting this value using the admin SDK [2] results in
{ child1: 'foo', child2: { key: 'bar } }
when calling.val()
, which is what you'd expect - all the empty/null
nodes are dropped.However using the
firebase-functions
database.DataSnapshot
constructor the result includes these empty/null
values{ child: 'foo', nullChild: null, emptyChild: {}, emptyArray: {}, child: { nullVal: null, key: 'bar' } }
when calling.val()
.I think this is mostly due to the lack of this check the
@firebase/database
does when calling.val()
.The discrepancies are mainly when using
.val()
but I've updated the other methods and their tests (.exists()
,.numChildren()
,.hasChildren()
, etc.) for completeness...[1] noticed when using
firebase-functions-test
makeDataSnapshot
method (which calls this reposdatabase.DataSnapshot
constructor) for mocking parameters for testing a Firebase Function.[2] By using: