1
- import { firestorePlugin } from '../../src'
2
- import { db , tick , Vue } from '@posva/vuefire-test-helpers '
1
+ import { firestorePlugin } from '../../../ src'
2
+ import { db , tick } from '../../src '
3
3
import { firestore } from 'firebase'
4
- import { CombinedVueInstance } from 'vue/types/vue'
5
-
6
- Vue . use ( firestorePlugin )
4
+ import { ComponentPublicInstance } from 'vue'
5
+ import { mount , VueWrapper } from '@vue/test-utils'
7
6
8
7
describe ( 'Firestore: firestore option' , ( ) => {
9
- let collection : firestore . CollectionReference ,
10
- document : firestore . DocumentReference ,
11
- vm : CombinedVueInstance <
12
- Vue ,
13
- { items : any [ ] ; item : any } ,
14
- object ,
15
- object ,
16
- Record < never , any >
17
- >
8
+ let collection : firestore . CollectionReference
9
+ let document : firestore . DocumentReference
10
+ let vm : ComponentPublicInstance & { items : any [ ] ; item : any }
11
+ let wrapper : VueWrapper < ComponentPublicInstance & { items : any [ ] ; item : any } >
18
12
beforeEach ( async ( ) => {
19
13
// @ts -ignore
20
14
collection = db . collection ( )
21
15
document = collection . doc ( )
22
- // @ts -ignore
23
- vm = new Vue ( {
24
- // purposely set items as null
25
- // but it's a good practice to set it to an empty array
26
- data : ( ) => ( {
27
- items : null ,
28
- item : null ,
29
- } ) ,
30
- firestore : {
31
- items : collection ,
32
- item : document ,
16
+ wrapper = mount (
17
+ {
18
+ template : 'no' ,
19
+ // purposely set items as null
20
+ // but it's a good practice to set it to an empty array
21
+ data : ( ) => ( {
22
+ items : null ,
23
+ item : null ,
24
+ } ) ,
25
+ firestore : {
26
+ items : collection ,
27
+ item : document ,
28
+ } ,
33
29
} ,
34
- } )
30
+ { global : { plugins : [ firestorePlugin ] } }
31
+ )
35
32
await tick ( )
33
+ vm = wrapper . vm
36
34
} )
37
35
38
36
it ( 'does nothing with no firestore' , ( ) => {
39
- const vm = new Vue ( {
37
+ const wrapper = mount ( {
40
38
data : ( ) => ( { items : null } ) ,
41
39
} )
42
- expect ( vm . items ) . toEqual ( null )
43
- } )
44
-
45
- it ( 'setups _firestoreUnbinds' , ( ) => {
46
- expect ( vm . _firestoreUnbinds ) . toBeTruthy ( )
47
- expect ( Object . keys ( vm . _firestoreUnbinds ) . sort ( ) ) . toEqual ( [ 'item' , 'items' ] )
40
+ expect ( wrapper . vm . items ) . toEqual ( null )
48
41
} )
49
42
50
- it ( 'setups _firestoreUnbinds with no firestore options' , ( ) => {
51
- const vm = new Vue ( {
52
- data : ( ) => ( { items : null } ) ,
53
- } )
54
- expect ( vm . _firestoreUnbinds ) . toBeTruthy ( )
55
- expect ( Object . keys ( vm . _firestoreUnbinds ) ) . toEqual ( [ ] )
43
+ it ( 'ignores no return' , ( ) => {
44
+ const spy = jest . fn ( )
45
+ mount (
46
+ {
47
+ // @ts -ignore: only care about not crashing
48
+ firestore : ( ) => { } ,
49
+ data : ( ) => ( { items : null } ) ,
50
+ } ,
51
+ {
52
+ global : {
53
+ config : {
54
+ errorHandler : spy ,
55
+ } ,
56
+ } ,
57
+ }
58
+ )
59
+ expect ( spy ) . not . toHaveBeenCalled ( )
56
60
} )
57
61
58
62
it ( 'setups $firestoreRefs' , ( ) => {
@@ -62,7 +66,7 @@ describe('Firestore: firestore option', () => {
62
66
} )
63
67
64
68
it ( 'clears $firestoreRefs on $destroy' , ( ) => {
65
- vm . $destroy ( )
69
+ wrapper . unmount ( )
66
70
expect ( vm . $firestoreRefs ) . toEqual ( null )
67
71
} )
68
72
} )
0 commit comments