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'
94
105describe ( 'RTDB: plugin options' , ( ) => {
116 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' )
1625 } )
1726
1827 it ( 'calls custom serialize function with collection' , async ( ) => {
19- const LocalVue = createLocalVue ( )
2028 const pluginOptions = {
2129 serialize : jest . fn ( ( ) => ( { foo : 'bar' } ) ) ,
2230 }
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+ )
2442
2543 const items = new MockFirebase ( ) . child ( 'data' )
26- const vm = new LocalVue ( {
27- data : ( ) => ( { items : [ ] } ) ,
28- } )
2944
3045 const p = vm . $rtdbBind ( 'items' , items )
3146 items . push ( { text : 'foo' } )
@@ -41,16 +56,22 @@ describe('RTDB: plugin options', () => {
4156 } )
4257
4358 it ( 'can be ovrriden by local option' , async ( ) => {
44- const LocalVue = createLocalVue ( )
4559 const pluginOptions = {
4660 serialize : jest . fn ( ( ) => ( { foo : 'bar' } ) ) ,
4761 }
48- LocalVue . use ( rtdbPlugin , pluginOptions )
4962
5063 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+ )
5475
5576 const spy = jest . fn ( ( ) => ( { bar : 'bar' } ) )
5677
0 commit comments