@@ -8,88 +8,69 @@ import {
8
8
} from '../../src'
9
9
import { setupDatabaseRefs } from '../utils'
10
10
11
- const component = defineComponent ( { template : 'no' } )
11
+ const component = defineComponent ( {
12
+ template : 'no' ,
13
+ data : ( ) => ( { items : [ ] , item : null } ) ,
14
+ } )
12
15
13
16
describe ( 'RTDB: plugin options' , ( ) => {
14
17
const { databaseRef, push } = setupDatabaseRefs ( )
15
18
16
- it ( 'allows customizing $rtdbBind' , ( ) => {
17
- const wrapper = mount ( component , {
18
- global : {
19
- plugins : [
20
- [
21
- databasePlugin ,
22
- {
23
- bindName : '$myBind' ,
24
- unbindName : '$myUnbind' ,
25
- } ,
26
- ] ,
27
- ] ,
28
- } ,
29
- } )
30
- expect ( typeof ( wrapper . vm as any ) . $myBind ) . toBe ( 'function' )
31
- expect ( typeof ( wrapper . vm as any ) . $myUnbind ) . toBe ( 'function' )
32
- } )
33
-
34
- it ( 'calls custom serialize function with a ref' , async ( ) => {
35
- const pluginOptions : DatabasePluginOptions = {
36
- serialize : vi . fn ( ( ) => ( { id : '2' , foo : 'bar' } ) ) ,
37
- }
38
- const { vm } = mount (
39
- {
40
- template : 'no' ,
41
- data : ( ) => ( { items : [ ] } ) ,
42
- } ,
43
- {
19
+ describe ( '$rtdbBind' , ( ) => {
20
+ function factory ( pluginOptions ?: DatabasePluginOptions ) {
21
+ return mount ( component , {
44
22
global : {
45
23
plugins : [ [ databasePlugin , pluginOptions ] ] ,
46
24
} ,
47
- }
48
- )
25
+ } )
26
+ }
49
27
50
- const itemListRef = databaseRef ( )
28
+ it ( 'allows customizing $rtdbBind' , ( ) => {
29
+ const wrapper = factory ( {
30
+ bindName : '$myBind' ,
31
+ unbindName : '$myUnbind' ,
32
+ } )
33
+ expect ( typeof ( wrapper . vm as any ) . $myBind ) . toBe ( 'function' )
34
+ expect ( typeof ( wrapper . vm as any ) . $myUnbind ) . toBe ( 'function' )
35
+ } )
51
36
52
- const p = vm . $rtdbBind ( 'items' , itemListRef )
53
- await push ( itemListRef , { text : 'foo' } )
37
+ it ( 'calls custom serialize function with a ref' , async ( ) => {
38
+ const serialize = vi . fn ( ( ) => ( { id : '2' , foo : 'bar' } ) )
39
+ const { vm } = factory ( { serialize } )
54
40
55
- expect ( pluginOptions . serialize ) . toHaveBeenCalledTimes ( 1 )
56
- expect ( pluginOptions . serialize ) . toHaveBeenCalledWith (
57
- expect . objectContaining ( { val : expect . any ( Function ) } )
58
- )
59
- expect ( vm . items ) . toEqual ( [ { foo : 'bar' , id : '2' } ] )
60
- } )
41
+ const itemListRef = databaseRef ( )
61
42
62
- it ( 'can override serialize with local option' , async ( ) => {
63
- const pluginOptions : DatabasePluginOptions = {
64
- serialize : vi . fn ( ( ) => ( { id : '2' , foo : 'bar' } ) ) ,
65
- }
43
+ const p = vm . $rtdbBind ( 'items' , itemListRef )
44
+ await push ( itemListRef , { text : 'foo' } )
66
45
67
- const items = databaseRef ( )
68
- const { vm } = mount (
69
- {
70
- template : 'no' ,
71
- data : ( ) => ( { items : [ ] } ) ,
72
- } ,
73
- {
74
- global : {
75
- plugins : [ [ databasePlugin , pluginOptions ] ] ,
76
- } ,
77
- }
78
- )
46
+ expect ( serialize ) . toHaveBeenCalledTimes ( 1 )
47
+ expect ( serialize ) . toHaveBeenCalledWith (
48
+ expect . objectContaining ( { val : expect . any ( Function ) } )
49
+ )
50
+ expect ( vm . items ) . toEqual ( [ { foo : 'bar' , id : '2' } ] )
51
+ } )
52
+
53
+ it ( 'can override serialize with local option' , async ( ) => {
54
+ const serialize = vi . fn ( ( ) => ( { id : '2' , foo : 'bar' } ) )
55
+ const items = databaseRef ( )
56
+ const { vm } = factory ( { serialize } )
79
57
80
- const spy : DatabaseSnapshotSerializer = vi . fn ( ( ) => ( {
81
- id : '3' ,
82
- bar : 'bar' ,
83
- } ) )
58
+ const spy : DatabaseSnapshotSerializer = vi . fn ( ( ) => ( {
59
+ id : '3' ,
60
+ bar : 'bar' ,
61
+ } ) )
84
62
85
- vm . $rtdbBind ( 'items' , items , { serialize : spy } )
86
- await push ( items , { text : 'foo' } )
63
+ vm . $rtdbBind ( 'items' , items , { serialize : spy } )
64
+ await push ( items , { text : 'foo' } )
87
65
88
- expect ( pluginOptions . serialize ) . not . toHaveBeenCalled ( )
89
- expect ( spy ) . toHaveBeenCalledTimes ( 1 )
90
- expect ( spy ) . toHaveBeenCalledWith (
91
- expect . objectContaining ( { val : expect . any ( Function ) } )
92
- )
93
- expect ( vm . items ) . toEqual ( [ { bar : 'bar' , id : '3' } ] )
66
+ expect ( serialize ) . not . toHaveBeenCalled ( )
67
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
68
+ expect ( spy ) . toHaveBeenCalledWith (
69
+ expect . objectContaining ( { val : expect . any ( Function ) } )
70
+ )
71
+ expect ( vm . items ) . toEqual ( [ { bar : 'bar' , id : '3' } ] )
72
+ } )
94
73
} )
74
+
75
+ // describe('firebase option', () => {})
95
76
} )
0 commit comments