Skip to content

Commit fb7ef54

Browse files
committed
Failing tests for accessing snapshot data with multiple paths
1 parent 8d26314 commit fb7ef54

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

test/unit/snapshot.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ describe('DataSnapshot', function () {
6363
expect(child.val()).to.equal('val');
6464
});
6565

66+
it('uses child data starting with /', function () {
67+
var parent = new Snapshot(ref, {key: 'val'});
68+
var child = parent.child('/key');
69+
expect(child.val()).to.equal('val');
70+
});
71+
72+
it('uses child data ending with /', function () {
73+
var parent = new Snapshot(ref, {key: 'val'});
74+
var child = parent.child('key/');
75+
expect(child.val()).to.equal('val');
76+
});
77+
6678
it('uses child data for false values', function () {
6779
var parent = new Snapshot(ref, {key: false});
6880
var child = parent.child('key');
@@ -75,6 +87,24 @@ describe('DataSnapshot', function () {
7587
expect(child.val()).to.equal(0);
7688
});
7789

90+
it('uses child data when accessing with multiple paths', function () {
91+
var parent = new Snapshot(ref, { key: { value: 'val' }});
92+
var child = parent.child('key/value');
93+
expect(child.val()).to.equal('val');
94+
});
95+
96+
it('uses child data when accessing with multiple paths for false values', function () {
97+
var parent = new Snapshot(ref, { key: { value: false }});
98+
var child = parent.child('key/value');
99+
expect(child.val()).to.equal(false);
100+
});
101+
102+
it('uses child data when accessing with multiple paths for 0 values', function () {
103+
var parent = new Snapshot(ref, { key: { value: 0 }});
104+
var child = parent.child('key/value');
105+
expect(child.val()).to.equal(0);
106+
});
107+
78108
it('uses null when there is no child data', function () {
79109
var parent = new Snapshot(ref);
80110
var child = parent.child('key');
@@ -137,6 +167,24 @@ describe('DataSnapshot', function () {
137167
expect(snapshot.hasChild('bar')).to.equal(false);
138168
});
139169

170+
it('tests for the key starting with /', function () {
171+
var snapshot = new Snapshot(ref, {foo: 'bar'});
172+
expect(snapshot.hasChild('/foo')).to.equal(true);
173+
expect(snapshot.hasChild('/bar')).to.equal(false);
174+
});
175+
176+
it('tests for the key ending with /', function () {
177+
var snapshot = new Snapshot(ref, {foo: 'bar'});
178+
expect(snapshot.hasChild('foo/')).to.equal(true);
179+
expect(snapshot.hasChild('bar/')).to.equal(false);
180+
});
181+
182+
it('tests for the key with multiple paths', function () {
183+
var snapshot = new Snapshot(ref, {key: {foo: 'bar'}});
184+
expect(snapshot.hasChild('key/foo')).to.equal(true);
185+
expect(snapshot.hasChild('key/bar')).to.equal(false);
186+
});
187+
140188
});
141189

142190
describe('#hasChildren', function () {

0 commit comments

Comments
 (0)