From 72f10fb1f43acbbcf6749b6eb23828c97716edb2 Mon Sep 17 00:00:00 2001 From: addisonssense Date: Thu, 16 May 2019 10:37:33 -0400 Subject: [PATCH] issue-1146: updated so that pretty printing html is default --- flow/wrapper.flow.js | 1 - packages/test-utils/src/wrapper.js | 5 +- test/specs/mount.spec.js | 9 ++- .../mounting-options/scopedSlots.spec.js | 69 +++++++++++-------- test/specs/mounting-options/slots.spec.js | 17 +++-- test/specs/shallow-mount.spec.js | 51 +++++++------- test/specs/wrapper/html.spec.js | 11 +-- 7 files changed, 83 insertions(+), 80 deletions(-) diff --git a/flow/wrapper.flow.js b/flow/wrapper.flow.js index 47f2b5de9..176a9c05c 100644 --- a/flow/wrapper.flow.js +++ b/flow/wrapper.flow.js @@ -5,7 +5,6 @@ import type WrapperArray from '~src/WrapperArray' declare type Selector = any declare type Components = { [name: string]: Component } -declare type HtmlOptions = { prettyPrint: boolean } declare interface BaseWrapper { // eslint-disable-line no-undef diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 5b8ba5b63..60346ce9a 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -222,10 +222,7 @@ export default class Wrapper implements BaseWrapper { /** * Returns HTML of element as a string */ - html(options?: HtmlOptions): string { - if (options && !options.prettyPrint) { - return this.element.outerHTML - } + html(): string { return pretty(this.element.outerHTML) } diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index f59176c0e..9bf2493d7 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -340,9 +340,12 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { if (vueVersion > 2.3) { expect(wrapper.vm.$attrs).to.eql({ height: '50px', extra: 'attr' }) } - const htmlOptions = { prettyPrint: false } - expect(wrapper.html(htmlOptions)).to.equal( - `

prop1

` + + expect(wrapper.html()).to.equal( + '
\n' + + '

prop1

\n' + + '

\n' + + '
' ) }) diff --git a/test/specs/mounting-options/scopedSlots.spec.js b/test/specs/mounting-options/scopedSlots.spec.js index 8be4820c4..511c4423a 100644 --- a/test/specs/mounting-options/scopedSlots.spec.js +++ b/test/specs/mounting-options/scopedSlots.spec.js @@ -7,7 +7,6 @@ import Vue from 'vue' describeWithShallowAndMount('scopedSlots', mountingMethod => { const sandbox = sinon.createSandbox() const windowSave = window - const htmlOptions = { prettyPrint: false } afterEach(() => { window = windowSave // eslint-disable-line no-native-reassign @@ -29,7 +28,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(wrapper.html(htmlOptions)).to.equal('

bar,123

') + expect(wrapper.html()).to.equal('
\n' + '

bar,123

\n' + '
') }) itDoNotRunIf(vueVersion < 2.1, 'handles render functions', () => { @@ -48,7 +47,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(wrapper.html(htmlOptions)).to.equal('

bar

') + expect(wrapper.html()).to.equal('
\n' + '

bar

\n' + '
') }) itDoNotRunIf( @@ -88,7 +87,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(notDestructuringWrapper.html(htmlOptions)).to.equal('

1,foo

') + expect(notDestructuringWrapper.html()).to.equal('

1,foo

') } ) @@ -113,7 +112,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(destructuringWrapper.html(htmlOptions)).to.equal('

1,foo

') + expect(destructuringWrapper.html()).to.equal('

1,foo

') const notDestructuringWrapper = mountingMethod( { @@ -131,7 +130,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(notDestructuringWrapper.html(htmlOptions)).to.equal('

1,foo

') + expect(notDestructuringWrapper.html()).to.equal('

1,foo

') } ) @@ -146,39 +145,55 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { noProps: '

baz

' } }) - expect(wrapper.find('#destructuring').html(htmlOptions)).to.equal( - '

0,1

1,2

2,3

' + expect(wrapper.find('#destructuring').html()).to.equal( + '
\n' + + '

0,1

\n' + + '

1,2

\n' + + '

2,3

\n' + + '
' ) - expect(wrapper.find('#slots').html(htmlOptions)).to.equal( + expect(wrapper.find('#slots').html()).to.equal( '
123
' ) - expect(wrapper.find('#list').html(htmlOptions)).to.equal( - '

0,a1

1,a2

2,a3

' + expect(wrapper.find('#list').html()).to.equal( + '
\n' + + '

0,a1

\n' + + '

1,a2

\n' + + '

2,a3

\n' + + '
' ) - expect(wrapper.find('#single').html(htmlOptions)).to.equal( - '

abc

' + expect(wrapper.find('#single').html()).to.equal( + '
\n' + '

abc

\n' + '
' ) - expect(wrapper.find('#noProps').html(htmlOptions)).to.equal( - '

baz

' + expect(wrapper.find('#noProps').html()).to.equal( + '
\n' + '

baz

\n' + '
' ) wrapper.vm.items = [4, 5, 6] wrapper.vm.foo = [{ text: 'b1' }, { text: 'b2' }, { text: 'b3' }] wrapper.vm.bar = 'ABC' await Vue.nextTick() - expect(wrapper.find('#destructuring').html(htmlOptions)).to.equal( - '

0,4

1,5

2,6

' + expect(wrapper.find('#destructuring').html()).to.equal( + '
\n' + + '

0,4

\n' + + '

1,5

\n' + + '

2,6

\n' + + '
' ) - expect(wrapper.find('#slots').html(htmlOptions)).to.equal( + expect(wrapper.find('#slots').html()).to.equal( '
123
' ) - expect(wrapper.find('#list').html(htmlOptions)).to.equal( - '

0,b1

1,b2

2,b3

' + expect(wrapper.find('#list').html()).to.equal( + '
\n' + + '

0,b1

\n' + + '

1,b2

\n' + + '

2,b3

\n' + + '
' ) - expect(wrapper.find('#single').html(htmlOptions)).to.equal( - '

ABC

' + expect(wrapper.find('#single').html()).to.equal( + '
\n' + '

ABC

\n' + '
' ) - expect(wrapper.find('#noProps').html(htmlOptions)).to.equal( - '

baz

' + expect(wrapper.find('#noProps').html()).to.equal( + '
\n' + '

baz

\n' + '
' ) }) @@ -198,7 +213,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(wrapper.html(htmlOptions)).to.equal('

bar

') + expect(wrapper.html()).to.equal('
\n' + '

bar

\n' + '
') }) itDoNotRunIf(vueVersion < 2.5, 'handles no slot-scope', () => { @@ -215,7 +230,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(wrapper.html(htmlOptions)).to.equal('

bar,123

') + expect(wrapper.html()).to.equal('
\n' + '

bar,123

\n' + '
') }) itDoNotRunIf( @@ -287,7 +302,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { localVue }) - expect(wrapper.html(htmlOptions)).to.contain('span') + expect(wrapper.html()).to.contain('span') } ) }) diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index c9b88d00e..063b809c9 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -8,8 +8,6 @@ import { itDoNotRunIf } from 'conditional-specs' import { mount, createLocalVue } from '~vue/test-utils' describeWithShallowAndMount('options.slots', mountingMethod => { - const htmlOptions = { prettyPrint: false } - it('mounts component with default slot if passed component in slot object', () => { const wrapper = mountingMethod(ComponentWithSlots, { slots: { default: Component } @@ -182,8 +180,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => { footer: '

world

' } }) - expect(wrapper.html(htmlOptions)).to.contain('hello') - expect(wrapper.html(htmlOptions)).to.contain('

world

') + expect(wrapper.html()).to.contain('hello') + expect(wrapper.html()).to.contain('

world

') }) it('mounts component with default and named text slot', () => { @@ -498,8 +496,11 @@ describeWithShallowAndMount('options.slots', mountingMethod => { c => c.$options.name === childComponentName ) ).to.equal(true) - expect(ParentComponent.html(htmlOptions)).to.equal( - '
FOO,quux
FOO,quux
' + expect(ParentComponent.html()).to.equal( + '
\n' + + '
FOO,quux
\n' + + '
FOO,quux
\n' + + '
' ) ParentComponent = mount( @@ -531,6 +532,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => { c => c.$options.name === childComponentName ) ).to.equal(true) - expect(ParentComponent.html(htmlOptions)).to.equal('

1234

') + expect(ParentComponent.html()).to.equal( + '
\n' + '

1234

\n' + '
' + ) }) }) diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 39c9ef981..da422f3a3 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -13,8 +13,6 @@ import { describeRunIf, itDoNotRunIf } from 'conditional-specs' describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const sandbox = sinon.createSandbox() - const htmlOptions = { prettyPrint: false } - beforeEach(() => { sandbox.stub(console, 'info').callThrough() sandbox.stub(console, 'error').callThrough() @@ -71,7 +69,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html(htmlOptions)).to.equal('Hello') + expect(wrapper.html()).to.equal('Hello') }) it('renders named slots', () => { @@ -90,8 +88,11 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html(htmlOptions)).to.equal( - '

Hello

World

' + expect(wrapper.html()).to.equal( + '\n' + + '

Hello

\n' + + '

World

\n' + + '
' ) }) @@ -101,7 +102,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components: { Child: {} } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.equal('') + expect(wrapper.html()).to.equal('') }) it('renders children for functional components', () => { @@ -116,7 +117,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html(htmlOptions)).to.equal('Hello') + expect(wrapper.html()).to.equal('Hello') }) it('stubs globally registered components', () => { @@ -172,9 +173,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.contain( - ' { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.contain(' { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.contain( - ' { @@ -229,7 +226,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.contain('`, data: () => ({ @@ -238,7 +235,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components } const wrapper2 = shallowMount(TestComponent2) - expect(wrapper2.html(htmlOptions)).to.contain('`, data: () => ({ @@ -247,7 +244,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components } const wrapper3 = shallowMount(TestComponent3) - expect(wrapper3.html(htmlOptions)).to.contain(' { @@ -260,7 +257,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { name: 'test-component' } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.contain('') + expect(wrapper.html()).to.contain('') expect(console.error).not.calledWith('[Vue warn]') }) @@ -427,9 +424,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.equal( - '' - ) + expect(wrapper.html()).to.equal('') }) it('stubs lazily registered components', () => { @@ -476,7 +471,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { localVue.use(myPlugin) const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html(htmlOptions)).to.contain('registered-component-stub') + expect(wrapper.html()).to.contain('registered-component-stub') }) it('throws an error when the component fails to mount', () => { @@ -524,12 +519,12 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html(htmlOptions)).to.equal( - '
' + - ' ' + - ' ' + - ' ' + - '' + + expect(wrapper.html()).to.equal( + '
\n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + '
' ) }) diff --git a/test/specs/wrapper/html.spec.js b/test/specs/wrapper/html.spec.js index 1ccd3412c..50f8d809a 100644 --- a/test/specs/wrapper/html.spec.js +++ b/test/specs/wrapper/html.spec.js @@ -32,7 +32,7 @@ describeWithShallowAndMount('html', mountingMethod => { expect(wrapper.html()).to.equal('
') }) - it('returns a Wrappers HTML as a string', () => { + it('returns a Wrappers HTML as a pretty printed string', () => { const expectedHtml = '\n' + '
\n' + @@ -47,13 +47,4 @@ describeWithShallowAndMount('html', mountingMethod => { const wrapper = mountingMethod(compiled) expect(wrapper.html()).to.equal(expectedHtml) }) - - it('returns a Wrappers HTML not as a pretty printed string', () => { - const expectedHtml = '
' - - const compiled = compileToFunctions(expectedHtml) - const wrapper = mountingMethod(compiled) - const options = { prettyPrint: false } - expect(wrapper.html(options)).to.equal(expectedHtml) - }) })