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 '
33import { 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'
76
87describe ( '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 } >
1812 beforeEach ( async ( ) => {
1913 // @ts -ignore
2014 collection = db . collection ( )
2115 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+ } ,
3329 } ,
34- } )
30+ { global : { plugins : [ firestorePlugin ] } }
31+ )
3532 await tick ( )
33+ vm = wrapper . vm
3634 } )
3735
3836 it ( 'does nothing with no firestore' , ( ) => {
39- const vm = new Vue ( {
37+ const wrapper = mount ( {
4038 data : ( ) => ( { items : null } ) ,
4139 } )
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 )
4841 } )
4942
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 ( )
5660 } )
5761
5862 it ( 'setups $firestoreRefs' , ( ) => {
@@ -62,7 +66,7 @@ describe('Firestore: firestore option', () => {
6266 } )
6367
6468 it ( 'clears $firestoreRefs on $destroy' , ( ) => {
65- vm . $destroy ( )
69+ wrapper . unmount ( )
6670 expect ( vm . $firestoreRefs ) . toEqual ( null )
6771 } )
6872} )
0 commit comments