@@ -324,6 +324,77 @@ export default class Wrapper implements BaseWrapper {
324324 return this . vnode . tag
325325 }
326326
327+ /**
328+ * Prints a simple overview of the wrapper current state
329+ * with useful information for debugging
330+ */
331+ overview ( ) : void {
332+ if ( ! this . isVueInstance ( ) ) {
333+ throwError ( `wrapper.overview() can only be called on a Vue instance` )
334+ }
335+
336+ const identation = 4
337+ const formatJSON = ( json : any , replacer : Function | null = null ) =>
338+ JSON . stringify ( json , replacer , identation ) . replace ( / " / g, '' )
339+
340+ const visibility = this . isVisible ( ) ? 'Visible' : 'Not visible'
341+
342+ const html = this . html ( )
343+ ? this . html ( ) . replace ( / ^ (? ! \s * $ ) / gm, ' ' . repeat ( identation ) ) + '\n'
344+ : ''
345+
346+ // $FlowIgnore
347+ const data = formatJSON ( this . vm . $data )
348+
349+ /* eslint-disable operator-linebreak */
350+ // $FlowIgnore
351+ const computed = this . vm . _computedWatchers
352+ ? formatJSON (
353+ // $FlowIgnore
354+ ...Object . keys ( this . vm . _computedWatchers ) . map ( computedKey => ( {
355+ // $FlowIgnore
356+ [ computedKey ] : this . vm [ computedKey ]
357+ } ) )
358+ )
359+ : // $FlowIgnore
360+ this . vm . $options . computed
361+ ? formatJSON (
362+ // $FlowIgnore
363+ ...Object . entries ( this . vm . $options . computed ) . map ( ( [ key , value ] ) => ( {
364+ // $FlowIgnore
365+ [ key ] : value ( )
366+ } ) )
367+ )
368+ : '{}'
369+ /* eslint-enable operator-linebreak */
370+
371+ const emittedJSONReplacer = ( key , value ) =>
372+ value instanceof Array
373+ ? value . map ( ( calledWith , index ) => {
374+ const callParams = calledWith . map ( param =>
375+ typeof param === 'object'
376+ ? JSON . stringify ( param )
377+ . replace ( / " / g, '' )
378+ . replace ( / , / g, ', ' )
379+ : param
380+ )
381+
382+ return `${ index } : [ ${ callParams . join ( ', ' ) } ]`
383+ } )
384+ : value
385+
386+ const emitted = formatJSON ( this . emitted ( ) , emittedJSONReplacer )
387+
388+ console . log (
389+ '\n' +
390+ `Wrapper (${ visibility } ):\n\n` +
391+ `Html:\n${ html } \n` +
392+ `Data: ${ data } \n\n` +
393+ `Computed: ${ computed } \n\n` +
394+ `Emitted: ${ emitted } \n`
395+ )
396+ }
397+
327398 /**
328399 * Returns an Object containing the prop name/value pairs on the element
329400 */
0 commit comments