From 76afc50bc4560e36b4ed35c96f999a9cb4ab2ce9 Mon Sep 17 00:00:00 2001 From: addisonssense Date: Thu, 9 May 2019 14:14:07 -0400 Subject: [PATCH] issue-1147: Add option to pretty print html components --- packages/test-utils/package.json | 3 ++- packages/test-utils/src/wrapper.js | 6 +++++- packages/test-utils/types/index.d.ts | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 495fb51b1..3d3300779 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -39,6 +39,7 @@ }, "dependencies": { "dom-event-types": "^1.0.0", - "lodash": "^4.17.4" + "lodash": "^4.17.4", + "pretty": "^2.0.0" } } diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 561674b48..90e106cb7 100644 --- a/packages/test-utils/src/wrapper.js +++ b/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' @@ -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 } diff --git a/packages/test-utils/types/index.d.ts b/packages/test-utils/types/index.d.ts index 89e29f028..769e338df 100644 --- a/packages/test-utils/types/index.d.ts +++ b/packages/test-utils/types/index.d.ts @@ -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