Skip to content

Commit 76afc50

Browse files
committed
issue-1147: Add option to pretty print html components
1 parent 23e496b commit 76afc50

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Diff for: packages/test-utils/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
},
4040
"dependencies": {
4141
"dom-event-types": "^1.0.0",
42-
"lodash": "^4.17.4"
42+
"lodash": "^4.17.4",
43+
"pretty": "^2.0.0"
4344
}
4445
}

Diff for: packages/test-utils/src/wrapper.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22

33
import Vue from 'vue'
4+
import pretty from 'pretty';
45
import getSelector from './get-selector'
56
import { REF_SELECTOR, FUNCTIONAL_OPTIONS, VUE_VERSION } from 'shared/consts'
67
import config from './config'
@@ -221,7 +222,10 @@ export default class Wrapper implements BaseWrapper {
221222
/**
222223
* Returns HTML of element as a string
223224
*/
224-
html(): string {
225+
html(options?: HtmlOptions): string {
226+
if (options && options.prettyPrint) {
227+
return pretty(this.element.outerHTML);
228+
}
225229
return this.element.outerHTML
226230
}
227231

Diff for: packages/test-utils/types/index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ type NameSelector = {
3939
name: string
4040
}
4141

42+
/**
43+
* Options when printing html components as strings
44+
*/
45+
export class HtmlOptions {
46+
prettyPrint: boolean
47+
}
48+
4249
/**
4350
* Base class of Wrapper and WrapperArray
4451
* It has common methods on both Wrapper and WrapperArray

0 commit comments

Comments
 (0)