@@ -86,6 +86,41 @@ describe('VueFire', function () {
86
86
} )
87
87
} )
88
88
89
+ it ( 'bind using $bindAsArray after $unbind' , function ( done ) {
90
+ var vm = new Vue ( {
91
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item.index }} </div></div>' ,
92
+ created : function ( ) {
93
+ this . $bindAsArray ( 'items' , firebaseRef )
94
+ }
95
+ } ) . $mount ( )
96
+ var firebaseRefOther = firebaseApp . database ( ) . ref ( ) . child ( helpers . generateRandomString ( ) )
97
+ firebaseRef . set ( {
98
+ first : { index : 0 } ,
99
+ second : { index : 1 } ,
100
+ third : { index : 2 }
101
+ } , function ( ) {
102
+ expect ( vm . items ) . to . deep . equal ( [
103
+ { '.key' : 'first' , index : 0 } ,
104
+ { '.key' : 'second' , index : 1 } ,
105
+ { '.key' : 'third' , index : 2 }
106
+ ] )
107
+ vm . $unbind ( 'items' )
108
+ vm . $bindAsArray ( 'items' , firebaseRefOther )
109
+ firebaseRefOther . set ( {
110
+ a : { index : 0 } ,
111
+ b : { index : 1 } ,
112
+ c : { index : 2 }
113
+ } , function ( ) {
114
+ expect ( vm . items ) . to . deep . equal ( [
115
+ { '.key' : 'a' , index : 0 } ,
116
+ { '.key' : 'b' , index : 1 } ,
117
+ { '.key' : 'c' , index : 2 }
118
+ ] )
119
+ done ( )
120
+ } )
121
+ } )
122
+ } )
123
+
89
124
it ( 'binds array records which are primitives' , function ( done ) {
90
125
var vm = new Vue ( {
91
126
firebase : {
@@ -531,6 +566,35 @@ describe('VueFire', function () {
531
566
} )
532
567
} )
533
568
569
+ it ( 'binds with $bindAsObject after $unbind' , function ( done ) {
570
+ var obj = {
571
+ first : { index : 0 } ,
572
+ second : { index : 1 } ,
573
+ third : { index : 2 }
574
+ }
575
+ var objOther = {
576
+ onlyOne : { index : 0 } ,
577
+ second : { index : 1 }
578
+ }
579
+ var vm = new Vue ( {
580
+ template : '<div>{{ items | json }}</div>' ,
581
+ created : function ( ) {
582
+ this . $bindAsObject ( 'items' , firebaseRef . child ( 'items' ) )
583
+ }
584
+ } ) . $mount ( )
585
+ firebaseRef . child ( 'items' ) . set ( obj , function ( ) {
586
+ obj [ '.key' ] = 'items'
587
+ expect ( vm . items ) . to . deep . equal ( obj )
588
+ vm . $unbind ( 'items' )
589
+ vm . $bindAsObject ( 'items' , firebaseRef . child ( 'others' ) )
590
+ firebaseRef . child ( 'others' ) . set ( objOther , function ( ) {
591
+ objOther [ '.key' ] = 'others'
592
+ expect ( vm . items ) . to . deep . equal ( objOther )
593
+ done ( )
594
+ } )
595
+ } )
596
+ } )
597
+
534
598
it ( 'binds with $bindAsObject' , function ( done ) {
535
599
var obj = {
536
600
first : { index : 0 } ,
0 commit comments