@@ -7,72 +7,88 @@ declare module '../../src/vueWrapper' {
7
7
width ( ) : number
8
8
$el : Element
9
9
myMethod ( ) : void
10
+ greet : ( name : string ) => string
10
11
}
11
12
}
12
13
13
14
const textValue = `I'm the innerHTML`
14
15
const mountComponent = ( ) => mount ( { template : `<h1>${ textValue } </h1>` } )
15
16
16
- describe ( 'Plugin' , ( ) => {
17
- describe ( '#install method' , ( ) => {
18
- beforeEach ( ( ) => {
19
- config . plugins . VueWrapper . reset ( )
20
- } )
21
-
22
- it ( 'extends wrappers with the return values from the install function' , ( ) => {
23
- const width = 230
24
- const plugin = ( ) => ( { width } )
25
- config . plugins . VueWrapper . install ( plugin )
26
- const wrapper = mountComponent ( )
27
- expect ( wrapper ) . toHaveProperty ( 'width' , width )
28
- } )
17
+ describe ( 'Plugin#install' , ( ) => {
18
+ beforeEach ( ( ) => {
19
+ config . plugins . VueWrapper . reset ( )
20
+ } )
29
21
30
- it ( 'receives the wrapper inside the plugin setup' , ( ) => {
31
- const plugin = ( wrapper : VueWrapper < ComponentPublicInstance > ) => {
32
- return {
33
- $el : wrapper . element // simple aliases
22
+ it ( 'accepts options' , ( ) => {
23
+ function PluginWithOptions (
24
+ wrapper : VueWrapper < ComponentPublicInstance > ,
25
+ options : Record < string , string >
26
+ ) {
27
+ return {
28
+ greet : ( name : string ) => {
29
+ return `${ options . msg } , ${ name } `
34
30
}
35
31
}
36
- config . plugins . VueWrapper . install ( plugin )
37
- const wrapper = mountComponent ( )
38
- expect ( wrapper . $el . innerHTML ) . toEqual ( textValue )
39
- } )
32
+ }
33
+ config . plugins . VueWrapper . install ( PluginWithOptions , { msg : 'Hello' } )
40
34
41
- it ( 'supports functions' , ( ) => {
42
- const myMethod = jest . fn ( )
43
- const plugin = ( ) => ( { myMethod } )
44
- config . plugins . VueWrapper . install ( plugin )
45
- mountComponent ( ) . myMethod ( )
46
- expect ( myMethod ) . toHaveBeenCalledTimes ( 1 )
47
- } )
35
+ const wrapper = mountComponent ( )
36
+ expect ( wrapper . greet ( 'Lachlan' ) ) . toBe ( 'Hello, Lachlan' )
37
+ } )
48
38
49
- describe ( 'error states' , ( ) => {
50
- beforeAll ( ( ) => {
51
- jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
52
- } )
39
+ it ( 'extends wrappers with the return values from the install function' , ( ) => {
40
+ const width = 230
41
+ const plugin = ( ) => ( { width } )
42
+ config . plugins . VueWrapper . install ( plugin )
43
+ const wrapper = mountComponent ( )
44
+ expect ( wrapper ) . toHaveProperty ( 'width' , width )
45
+ } )
53
46
54
- afterAll ( ( ) => {
55
- // @ts -ignore
56
- console . error . mockRestore ( )
57
- } )
47
+ it ( 'receives the wrapper inside the plugin setup' , ( ) => {
48
+ const plugin = ( wrapper : VueWrapper < ComponentPublicInstance > ) => {
49
+ return {
50
+ $el : wrapper . element // simple aliases
51
+ }
52
+ }
53
+ config . plugins . VueWrapper . install ( plugin )
54
+ const wrapper = mountComponent ( )
55
+ expect ( wrapper . $el . innerHTML ) . toEqual ( textValue )
56
+ } )
58
57
59
- const plugins = [
60
- ( ) => false ,
61
- ( ) => true ,
62
- ( ) => [ ] ,
63
- true ,
64
- false ,
65
- 'property' ,
66
- 120
67
- ]
58
+ it ( 'supports functions' , ( ) => {
59
+ const myMethod = jest . fn ( )
60
+ const plugin = ( ) => ( { myMethod } )
61
+ config . plugins . VueWrapper . install ( plugin )
62
+ mountComponent ( ) . myMethod ( )
63
+ expect ( myMethod ) . toHaveBeenCalledTimes ( 1 )
64
+ } )
68
65
69
- it . each ( plugins ) (
70
- 'Calling install with %p is handled gracefully' ,
71
- ( plugin ) => {
72
- config . plugins . VueWrapper . install ( plugin as any )
73
- expect ( ( ) => mountComponent ( ) ) . not . toThrow ( )
74
- }
75
- )
66
+ describe ( 'error states' , ( ) => {
67
+ beforeAll ( ( ) => {
68
+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
69
+ } )
70
+
71
+ afterAll ( ( ) => {
72
+ // @ts -ignore
73
+ console . error . mockRestore ( )
76
74
} )
75
+
76
+ const plugins = [
77
+ ( ) => false ,
78
+ ( ) => true ,
79
+ ( ) => [ ] ,
80
+ true ,
81
+ false ,
82
+ 'property' ,
83
+ 120
84
+ ]
85
+
86
+ it . each ( plugins ) (
87
+ 'Calling install with %p is handled gracefully' ,
88
+ ( plugin ) => {
89
+ config . plugins . VueWrapper . install ( plugin as any )
90
+ expect ( ( ) => mountComponent ( ) ) . not . toThrow ( )
91
+ }
92
+ )
77
93
} )
78
94
} )
0 commit comments