1- import { rtdbPlugin } from '../../src'
2- import { tick , Vue , MockFirebase } from '@posva/vuefire-test-helpers'
3-
4- Vue . use ( rtdbPlugin )
1+ import { mount } from '@vue/test-utils'
2+ import { rtdbPlugin } from '../../../src'
3+ import { tick , MockFirebase } from '../../src'
54
65describe ( 'RTDB: firebase option' , ( ) => {
76 async function createVm ( ) {
87 const source = new MockFirebase ( ) . child ( 'data' )
9- const vm = new Vue ( {
10- // purposely set items as null
11- // but it's a good practice to set it to an empty array
12- data : ( ) => ( {
13- items : [ ] ,
14- item : null ,
15- } ) ,
16- firebase : {
17- items : source ,
18- item : source ,
8+ const wrapper = mount (
9+ {
10+ template : 'no' ,
11+ data : ( ) => ( {
12+ items : [ ] ,
13+ item : null ,
14+ } ) ,
15+ firebase : {
16+ items : source ,
17+ item : source ,
18+ } ,
1919 } ,
20- } )
20+ {
21+ global : {
22+ plugins : [ rtdbPlugin ] ,
23+ } ,
24+ }
25+ )
2126 await tick ( )
2227
23- return { vm, source }
28+ return { vm : wrapper . vm , source, wrapper }
2429 }
2530
2631 it ( 'does nothing with no firebase' , ( ) => {
27- const vm = new Vue ( {
28- data : ( ) => ( { items : null } ) ,
29- } )
30- expect ( vm . items ) . toEqual ( null )
31- } )
32-
33- it ( 'setups _firebaseUnbinds' , async ( ) => {
34- const { vm } = await createVm ( )
35- expect ( vm . _firebaseUnbinds ) . toBeTruthy ( )
36- expect ( Object . keys ( vm . _firebaseUnbinds ) . sort ( ) ) . toEqual ( [ 'item' , 'items' ] )
32+ const wrapper = mount (
33+ {
34+ template : 'no' ,
35+ data : ( ) => ( { items : null } ) ,
36+ } ,
37+ { global : { plugins : [ rtdbPlugin ] } }
38+ )
39+ expect ( wrapper . vm . items ) . toEqual ( null )
3740 } )
3841
39- it ( 'setups _firebaseUnbinds with no firebase options' , ( ) => {
40- const vm = new Vue ( {
41- data : ( ) => ( { items : null } ) ,
42- } )
43- expect ( vm . _firebaseUnbinds ) . toBeTruthy ( )
44- expect ( Object . keys ( vm . _firebaseUnbinds ) ) . toEqual ( [ ] )
42+ it ( 'does nothing with empty firebase return' , ( ) => {
43+ const wrapper = mount (
44+ {
45+ template : 'no' ,
46+ data : ( ) => ( { items : null } ) ,
47+ // @ts -ignore
48+ firebase : ( ) => { } ,
49+ } ,
50+ { global : { plugins : [ rtdbPlugin ] } }
51+ )
52+ // @ts -ignore
53+ expect ( wrapper . vm . items ) . toEqual ( null )
4554 } )
4655
4756 it ( 'setups $firebaseRefs' , async ( ) => {
@@ -52,10 +61,8 @@ describe('RTDB: firebase option', () => {
5261 } )
5362
5463 it ( 'clears $firebaseRefs on $destroy' , async ( ) => {
55- const { vm } = await createVm ( )
56- vm . $destroy ( )
64+ const { vm, wrapper } = await createVm ( )
65+ wrapper . unmount ( )
5766 expect ( vm . $firebaseRefs ) . toEqual ( null )
58- expect ( vm . _firebaseUnbinds ) . toEqual ( null )
59- expect ( vm . _firebaseSources ) . toEqual ( null )
6067 } )
6168} )
0 commit comments