@@ -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,12 +87,36 @@ 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' ) ;
81111 expect ( child . val ( ) ) . to . equal ( null ) ;
82112 } ) ;
83113
114+ it ( 'uses null when there is no child data with multiple paths' , function ( ) {
115+ var parent = new Snapshot ( ref ) ;
116+ var child = parent . child ( 'key/value' ) ;
117+ expect ( child . val ( ) ) . to . equal ( null ) ;
118+ } ) ;
119+
84120 it ( 'passes the priority' , function ( ) {
85121 var parent = new Snapshot ( ref ) ;
86122 ref . child ( 'key' ) . setPriority ( 10 ) ;
@@ -89,6 +125,18 @@ describe('DataSnapshot', function () {
89125 expect ( child . getPriority ( ) ) . to . equal ( 10 ) ;
90126 } ) ;
91127
128+ it ( 'allows array indexes' , function ( ) {
129+ var parent = new Snapshot ( ref , [ 'foo' , 'bar' ] ) ;
130+ var child = parent . child ( 0 ) ;
131+ expect ( child . val ( ) ) . to . equal ( 'foo' ) ;
132+ } ) ;
133+
134+ it ( 'allows array indexes in multiple paths' , function ( ) {
135+ var parent = new Snapshot ( ref , { key : { array : [ 'foo' , 'bar' ] } } ) ;
136+ var child = parent . child ( 'key/array/1' ) ;
137+ expect ( child . val ( ) ) . to . equal ( 'bar' ) ;
138+ } ) ;
139+
92140 } ) ;
93141
94142 describe ( '#exists' , function ( ) {
@@ -137,6 +185,25 @@ describe('DataSnapshot', function () {
137185 expect ( snapshot . hasChild ( 'bar' ) ) . to . equal ( false ) ;
138186 } ) ;
139187
188+ it ( 'tests for the key starting with /' , function ( ) {
189+ var snapshot = new Snapshot ( ref , { foo : 'bar' } ) ;
190+ expect ( snapshot . hasChild ( '/foo' ) ) . to . equal ( true ) ;
191+ expect ( snapshot . hasChild ( '/bar' ) ) . to . equal ( false ) ;
192+ } ) ;
193+
194+ it ( 'tests for the key ending with /' , function ( ) {
195+ var snapshot = new Snapshot ( ref , { foo : 'bar' } ) ;
196+ expect ( snapshot . hasChild ( 'foo/' ) ) . to . equal ( true ) ;
197+ expect ( snapshot . hasChild ( 'bar/' ) ) . to . equal ( false ) ;
198+ } ) ;
199+
200+ it ( 'tests for the key with multiple paths' , function ( ) {
201+ var snapshot = new Snapshot ( ref , { key : { foo : 'bar' } } ) ;
202+ expect ( snapshot . hasChild ( 'key/foo' ) ) . to . equal ( true ) ;
203+ expect ( snapshot . hasChild ( 'key/bar' ) ) . to . equal ( false ) ;
204+ expect ( snapshot . hasChild ( 'foo/key' ) ) . to . equal ( false ) ;
205+ } ) ;
206+
140207 } ) ;
141208
142209 describe ( '#hasChildren' , function ( ) {
0 commit comments