@@ -56,14 +56,18 @@ const throwIfNotVueInstance = vm => {
56
56
// debugging breadcrumbs in case a non-Vue instance gets erroneously passed
57
57
// makes the error easier to fix than example: "Cannot read _prevClass of undefined"
58
58
console . error ( vm )
59
- throw new TypeError ( `The matcher function expects Vue instance. Given ${ typeof vm } ` )
59
+ throw new TypeError (
60
+ `The matcher function expects Vue instance. Given ${ typeof vm } `
61
+ )
60
62
}
61
63
}
62
64
63
65
const throwIfNotHTMLElement = el => {
64
66
if ( ! isHTMLElement ( el ) ) {
65
67
console . error ( el )
66
- throw new TypeError ( `The matcher function expects an HTML Element. Given ${ typeof el } ` )
68
+ throw new TypeError (
69
+ `The matcher function expects an HTML Element. Given ${ typeof el } `
70
+ )
67
71
}
68
72
}
69
73
@@ -93,17 +97,21 @@ const elHasClass = (el, className) => {
93
97
* @param {string } className
94
98
* @return {boolean }
95
99
*/
96
- const hasClass = ( node , className ) => ( isVueInstance ( node ) ? vmHasClass ( node , className ) : elHasClass ( node , className ) )
100
+ const hasClass = ( node , className ) =>
101
+ isVueInstance ( node )
102
+ ? vmHasClass ( node , className )
103
+ : elHasClass ( node , className )
97
104
98
105
const getVmTag = vm => vm . $options . _componentTag
99
106
const getHTMLTag = el => String ( el . tagName ) . toLowerCase ( )
100
- const getTagName = node => ( isVueInstance ( node ) ? getVmTag ( node ) : getHTMLTag ( node ) )
107
+ const getTagName = node =>
108
+ isVueInstance ( node ) ? getVmTag ( node ) : getHTMLTag ( node )
101
109
102
110
// Extend Jest marchers
103
111
expect . extend ( {
104
112
toHaveClass ( node , className ) {
105
113
return {
106
- message : `expected <${ getTagName ( node ) } > to have class '${ className } '` ,
114
+ message : ( ) => `expected <${ getTagName ( node ) } > to have class '${ className } '` ,
107
115
pass : hasClass ( node , className )
108
116
}
109
117
} ,
@@ -127,25 +135,29 @@ expect.extend({
127
135
128
136
return {
129
137
// more debugging breadcrumbs
130
- message : `Expected <${ tagName } > to have all classes in [${ classStr } ], but was missing [${ missingClassStr } ] class${ plural
131
- ? 'es'
132
- : '' } .`,
138
+ message : ( ) => `Expected <${ tagName } > to have all classes in [${ classStr } ], but was missing [${ missingClassStr } ] class${
139
+ plural ? 'es' : ' '
140
+ } .`,
133
141
pass
134
142
}
135
143
} ,
136
144
toBeComponent ( vm , componentTag ) {
137
145
throwIfNotVueInstance ( vm )
138
146
139
147
return {
140
- message : `Expected to be <${ componentTag } >. Received: ${ getVmTag ( vm ) } ` ,
148
+ message : ( ) =>
149
+ `Expected to be <${ componentTag } >. Received: ${ getVmTag ( vm ) } ` ,
141
150
pass : getVmTag ( vm ) === componentTag
142
151
}
143
152
} ,
144
153
toBeElement ( el , tagName ) {
145
154
throwIfNotHTMLElement ( el )
146
155
147
156
return {
148
- message : `Expected to be <${ String ( tagName ) . toLowerCase ( ) } >. Received: ${ el . tagName . toLowerCase ( ) } ` ,
157
+ message : ( ) =>
158
+ `Expected to be <${ String (
159
+ tagName
160
+ ) . toLowerCase ( ) } >. Received: ${ el . tagName . toLowerCase ( ) } `,
149
161
pass : el . tagName === String ( tagName ) . toUpperCase ( )
150
162
}
151
163
}
0 commit comments