1
- import { rtdbPlugin } from '../../src'
2
- import { Vue , MockFirebase } from '@posva/vuefire-test-helpers'
3
-
4
- const createLocalVue = ( ) => {
5
- const newVue = Vue . extend ( )
6
- newVue . config = Vue . config
7
- return newVue
8
- }
1
+ import { mount } from '@vue/test-utils'
2
+ import { rtdbPlugin } from '../../../src'
3
+ import { MockFirebase } from '../../src'
9
4
10
5
describe ( 'RTDB: plugin options' , ( ) => {
11
6
it ( 'allows customizing $rtdbBind' , ( ) => {
12
- const LocalVue = createLocalVue ( )
13
- LocalVue . use ( rtdbPlugin , { bindName : '$bind' , unbindName : '$unbind' } )
14
- expect ( typeof LocalVue . prototype . $bind ) . toBe ( 'function' )
15
- expect ( typeof LocalVue . prototype . $unbind ) . toBe ( 'function' )
7
+ const wrapper = mount (
8
+ { template : 'n' } ,
9
+ {
10
+ global : {
11
+ plugins : [
12
+ [
13
+ rtdbPlugin ,
14
+ {
15
+ bindName : '$myBind' ,
16
+ unbindName : '$myUnbind' ,
17
+ } ,
18
+ ] ,
19
+ ] ,
20
+ } ,
21
+ }
22
+ )
23
+ expect ( typeof ( wrapper . vm as any ) . $myBind ) . toBe ( 'function' )
24
+ expect ( typeof ( wrapper . vm as any ) . $myUnbind ) . toBe ( 'function' )
16
25
} )
17
26
18
27
it ( 'calls custom serialize function with collection' , async ( ) => {
19
- const LocalVue = createLocalVue ( )
20
28
const pluginOptions = {
21
29
serialize : jest . fn ( ( ) => ( { foo : 'bar' } ) ) ,
22
30
}
23
- LocalVue . use ( rtdbPlugin , pluginOptions )
31
+ const { vm } = mount (
32
+ {
33
+ template : 'no' ,
34
+ data : ( ) => ( { items : [ ] } ) ,
35
+ } ,
36
+ {
37
+ global : {
38
+ plugins : [ [ rtdbPlugin , pluginOptions ] ] ,
39
+ } ,
40
+ }
41
+ )
24
42
25
43
const items = new MockFirebase ( ) . child ( 'data' )
26
- const vm = new LocalVue ( {
27
- data : ( ) => ( { items : [ ] } ) ,
28
- } )
29
44
30
45
const p = vm . $rtdbBind ( 'items' , items )
31
46
items . push ( { text : 'foo' } )
@@ -41,16 +56,22 @@ describe('RTDB: plugin options', () => {
41
56
} )
42
57
43
58
it ( 'can be ovrriden by local option' , async ( ) => {
44
- const LocalVue = createLocalVue ( )
45
59
const pluginOptions = {
46
60
serialize : jest . fn ( ( ) => ( { foo : 'bar' } ) ) ,
47
61
}
48
- LocalVue . use ( rtdbPlugin , pluginOptions )
49
62
50
63
const items = new MockFirebase ( ) . child ( 'data' )
51
- const vm = new LocalVue ( {
52
- data : ( ) => ( { items : [ ] } ) ,
53
- } )
64
+ const { vm } = mount (
65
+ {
66
+ template : 'no' ,
67
+ data : ( ) => ( { items : [ ] } ) ,
68
+ } ,
69
+ {
70
+ global : {
71
+ plugins : [ [ rtdbPlugin , pluginOptions ] ] ,
72
+ } ,
73
+ }
74
+ )
54
75
55
76
const spy = jest . fn ( ( ) => ( { bar : 'bar' } ) )
56
77
0 commit comments