@@ -20,19 +20,24 @@ import findAll from '../lib/find'
2020import createWrapper from './create-wrapper'
2121
2222export default class Wrapper implements BaseWrapper {
23- vnode : VNode ;
23+ vnode : VNode | null ;
2424 vm: Component | null ;
2525 _emitted: { [ name : string ] : Array < Array < any >> } ;
2626 _emittedByOrder: Array < { name : string ; args: Array < any > } > ;
2727 isVueComponent: boolean ;
28- element: HTMLElement ;
28+ element: Element ;
2929 update: Function ;
3030 options: WrapperOptions ;
3131 version: number
3232
33- constructor ( vnode : VNode , update : Function , options : WrapperOptions ) {
34- this . vnode = vnode
35- this . element = vnode . elm
33+ constructor ( node : VNode | Element , update : Function , options : WrapperOptions ) {
34+ if ( node instanceof Element ) {
35+ this . element = node
36+ this . vnode = null
37+ } else {
38+ this . vnode = node
39+ this . element = node . elm
40+ }
3641 this . update = update
3742 this . options = options
3843 this . version = Number ( `${ Vue . version . split ( '.' ) [ 0 ] } .${ Vue . version . split ( '.' ) [ 1 ] } ` )
@@ -82,7 +87,7 @@ export default class Wrapper implements BaseWrapper {
8287 */
8388 contains ( selector : Selector ) {
8489 const selectorType = getSelectorTypeOrThrow ( selector , 'contains' )
85- const nodes = findAll ( this . vm , this . vnode , selectorType , selector )
90+ const nodes = findAll ( this . vm , this . vnode , this . element , selector )
8691 const is = selectorType === REF_SELECTOR ? false : this . is ( selector )
8792 return nodes . length > 0 || is
8893 }
@@ -222,14 +227,15 @@ export default class Wrapper implements BaseWrapper {
222227 const body = document . querySelector ( 'body' )
223228 const mockElement = document . createElement ( 'div' )
224229
225- if ( ! ( body instanceof HTMLElement ) ) {
230+ if ( ! ( body instanceof Element ) ) {
226231 return false
227232 }
228233 const mockNode = body . insertBefore ( mockElement , null )
229234 // $FlowIgnore : Flow thinks style[style] returns a number
230235 mockElement . style [ style ] = value
231236
232- if ( ! this . options . attachedToDocument ) {
237+ if ( ! this . options . attachedToDocument && ( this . vm || this . vnode ) ) {
238+ // $FlowIgnore : Possible null value, will be removed in 1.0.0
233239 const vm = this . vm || this . vnode . context . $root
234240 body . insertBefore ( vm . $root . _vnode . elm , null )
235241 }
@@ -243,8 +249,7 @@ export default class Wrapper implements BaseWrapper {
243249 * Finds first node in tree of the current wrapper that matches the provided selector.
244250 */
245251 find ( selector : Selector ) : Wrapper | ErrorWrapper | VueWrapper {
246- const selectorType = getSelectorTypeOrThrow ( selector , 'find' )
247- const nodes = findAll ( this . vm , this . vnode , selectorType , selector )
252+ const nodes = findAll ( this . vm , this . vnode , this . element , selector )
248253 if ( nodes . length === 0 ) {
249254 if ( selector . ref ) {
250255 return new ErrorWrapper ( `ref="${ selector . ref } "` )
@@ -258,8 +263,8 @@ export default class Wrapper implements BaseWrapper {
258263 * Finds node in tree of the current wrapper that matches the provided selector.
259264 */
260265 findAll ( selector : Selector ) : WrapperArray {
261- const selectorType = getSelectorTypeOrThrow ( selector , 'findAll' )
262- const nodes = findAll ( this . vm , this . vnode , selectorType , selector )
266+ getSelectorTypeOrThrow ( selector , 'findAll' )
267+ const nodes = findAll ( this . vm , this . vnode , this . element , selector )
263268 const wrappers = nodes . map ( node =>
264269 createWrapper ( node , this . update , this . options )
265270 )
@@ -313,6 +318,9 @@ export default class Wrapper implements BaseWrapper {
313318 * Checks if node is empty
314319 */
315320 isEmpty ( ) : boolean {
321+ if ( ! this . vnode ) {
322+ return this . element . innerHTML === ''
323+ }
316324 return this . vnode . children === undefined || this . vnode . children . length === 0
317325 }
318326
@@ -331,6 +339,10 @@ export default class Wrapper implements BaseWrapper {
331339 return this . vm . $options . name
332340 }
333341
342+ if ( ! this . vnode ) {
343+ return this . element . tagName
344+ }
345+
334346 return this . vnode . tag
335347 }
336348
0 commit comments