Skip to content

Commit

Permalink
issue-1147: Add option to pretty print html components
Browse files Browse the repository at this point in the history
  • Loading branch information
addisonssense committed May 9, 2019
1 parent 23e496b commit 76afc50
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/test-utils/package.json
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"dom-event-types": "^1.0.0",
"lodash": "^4.17.4"
"lodash": "^4.17.4",
"pretty": "^2.0.0"
}
}
6 changes: 5 additions & 1 deletion packages/test-utils/src/wrapper.js
@@ -1,6 +1,7 @@
// @flow

import Vue from 'vue'
import pretty from 'pretty';
import getSelector from './get-selector'
import { REF_SELECTOR, FUNCTIONAL_OPTIONS, VUE_VERSION } from 'shared/consts'
import config from './config'
Expand Down Expand Up @@ -221,7 +222,10 @@ export default class Wrapper implements BaseWrapper {
/**
* Returns HTML of element as a string
*/
html(): string {
html(options?: HtmlOptions): string {
if (options && options.prettyPrint) {
return pretty(this.element.outerHTML);
}
return this.element.outerHTML
}

Expand Down
7 changes: 7 additions & 0 deletions packages/test-utils/types/index.d.ts
Expand Up @@ -39,6 +39,13 @@ type NameSelector = {
name: string
}

/**
* Options when printing html components as strings
*/
export class HtmlOptions {
prettyPrint: boolean
}

/**
* Base class of Wrapper and WrapperArray
* It has common methods on both Wrapper and WrapperArray
Expand Down

0 comments on commit 76afc50

Please sign in to comment.