@@ -5,12 +5,13 @@ import {
55 databasePlugin ,
66 DatabasePluginOptions ,
77 DatabaseSnapshotSerializer ,
8+ FirebaseOption ,
89} from '../../src'
910import { setupDatabaseRefs } from '../utils'
1011
1112const component = defineComponent ( {
1213 template : 'no' ,
13- data : ( ) => ( { items : [ ] , item : null } ) ,
14+ data : ( ) => ( { itemList : [ ] , item : null } ) ,
1415} )
1516
1617describe ( 'RTDB: plugin options' , ( ) => {
@@ -40,14 +41,14 @@ describe('RTDB: plugin options', () => {
4041
4142 const itemListRef = databaseRef ( )
4243
43- const p = vm . $rtdbBind ( 'items ' , itemListRef )
44+ const p = vm . $rtdbBind ( 'itemList ' , itemListRef )
4445 await push ( itemListRef , { text : 'foo' } )
4546
4647 expect ( serialize ) . toHaveBeenCalledTimes ( 1 )
4748 expect ( serialize ) . toHaveBeenCalledWith (
4849 expect . objectContaining ( { val : expect . any ( Function ) } )
4950 )
50- expect ( vm . items ) . toEqual ( [ { foo : 'bar' , id : '2' } ] )
51+ expect ( vm . itemList ) . toEqual ( [ { foo : 'bar' , id : '2' } ] )
5152 } )
5253
5354 it ( 'can override serialize with local option' , async ( ) => {
@@ -60,17 +61,46 @@ describe('RTDB: plugin options', () => {
6061 bar : 'bar' ,
6162 } ) )
6263
63- vm . $rtdbBind ( 'items ' , items , { serialize : spy } )
64+ vm . $rtdbBind ( 'itemList ' , items , { serialize : spy } )
6465 await push ( items , { text : 'foo' } )
6566
6667 expect ( serialize ) . not . toHaveBeenCalled ( )
6768 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
6869 expect ( spy ) . toHaveBeenCalledWith (
6970 expect . objectContaining ( { val : expect . any ( Function ) } )
7071 )
71- expect ( vm . items ) . toEqual ( [ { bar : 'bar' , id : '3' } ] )
72+ expect ( vm . itemList ) . toEqual ( [ { bar : 'bar' , id : '3' } ] )
7273 } )
7374 } )
7475
75- // describe('firebase option', () => {})
76+ describe ( 'firebase option' , ( ) => {
77+ function factory (
78+ firebase : FirebaseOption ,
79+ pluginOptions ?: DatabasePluginOptions
80+ ) {
81+ return mount ( component , {
82+ firebase,
83+ global : {
84+ plugins : [ [ databasePlugin , pluginOptions ] ] ,
85+ } ,
86+ } )
87+ }
88+
89+ it ( 'setups $firebaseRefs' , async ( ) => {
90+ const itemSource = databaseRef ( )
91+ const itemListSource = databaseRef ( )
92+ const { vm } = factory ( { item : itemSource , itemList : itemListSource } )
93+ expect ( Object . keys ( vm . $firebaseRefs ) . sort ( ) ) . toEqual ( [ 'item' , 'itemList' ] )
94+ expect ( vm . $firebaseRefs . item . key ) . toBe ( itemSource . key )
95+ expect ( vm . $firebaseRefs . itemList . key ) . toBe ( itemListSource . key )
96+ } )
97+
98+ it ( 'clears $firebaseRefs on unmount' , async ( ) => {
99+ const itemSource = databaseRef ( )
100+ const itemListSource = databaseRef ( )
101+ const wrapper = factory ( { item : itemSource , itemList : itemListSource } )
102+ wrapper . unmount ( )
103+ expect ( wrapper . vm . $firebaseRefs ) . toEqual ( null )
104+ } )
105+ } )
76106} )
0 commit comments