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'
5
4
6
5
describe ( 'RTDB: firebase option' , ( ) => {
7
6
async function createVm ( ) {
8
7
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
+ } ,
19
19
} ,
20
- } )
20
+ {
21
+ global : {
22
+ plugins : [ rtdbPlugin ] ,
23
+ } ,
24
+ }
25
+ )
21
26
await tick ( )
22
27
23
- return { vm, source }
28
+ return { vm : wrapper . vm , source, wrapper }
24
29
}
25
30
26
31
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 )
37
40
} )
38
41
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 )
45
54
} )
46
55
47
56
it ( 'setups $firebaseRefs' , async ( ) => {
@@ -52,10 +61,8 @@ describe('RTDB: firebase option', () => {
52
61
} )
53
62
54
63
it ( 'clears $firebaseRefs on $destroy' , async ( ) => {
55
- const { vm } = await createVm ( )
56
- vm . $destroy ( )
64
+ const { vm, wrapper } = await createVm ( )
65
+ wrapper . unmount ( )
57
66
expect ( vm . $firebaseRefs ) . toEqual ( null )
58
- expect ( vm . _firebaseUnbinds ) . toEqual ( null )
59
- expect ( vm . _firebaseSources ) . toEqual ( null )
60
67
} )
61
68
} )
0 commit comments