diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index 237abce2c..5b8ba5b63 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -223,10 +223,10 @@ export default class Wrapper implements BaseWrapper { * Returns HTML of element as a string */ html(options?: HtmlOptions): string { - if (options && options.prettyPrint) { - return pretty(this.element.outerHTML) + if (options && !options.prettyPrint) { + return this.element.outerHTML } - return this.element.outerHTML + return pretty(this.element.outerHTML) } /** diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 792b23118..f59176c0e 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -340,7 +340,8 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { if (vueVersion > 2.3) { expect(wrapper.vm.$attrs).to.eql({ height: '50px', extra: 'attr' }) } - expect(wrapper.html()).to.equal( + const htmlOptions = { prettyPrint: false } + expect(wrapper.html(htmlOptions)).to.equal( `

prop1

` ) }) diff --git a/test/specs/mounting-options/scopedSlots.spec.js b/test/specs/mounting-options/scopedSlots.spec.js index 6423aa46f..8be4820c4 100644 --- a/test/specs/mounting-options/scopedSlots.spec.js +++ b/test/specs/mounting-options/scopedSlots.spec.js @@ -7,6 +7,7 @@ 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 @@ -28,7 +29,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { } } ) - expect(wrapper.html()).to.equal('

bar,123

') + expect(wrapper.html(htmlOptions)).to.equal('

bar,123

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

bar

') + expect(wrapper.html(htmlOptions)).to.equal('

bar

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

1,foo

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

1,foo

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

1,foo

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

1,foo

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

1,foo

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

1,foo

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

baz

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

0,1

1,2

2,3

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

0,a1

1,a2

2,a3

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

abc

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

baz

' ) 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()).to.equal( + expect(wrapper.find('#destructuring').html(htmlOptions)).to.equal( '

0,4

1,5

2,6

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

0,b1

1,b2

2,b3

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

ABC

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

baz

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

bar

') + expect(wrapper.html(htmlOptions)).to.equal('

bar

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

bar,123

') + expect(wrapper.html(htmlOptions)).to.equal('

bar,123

') }) itDoNotRunIf( @@ -286,7 +287,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => { localVue }) - expect(wrapper.html()).to.contain('span') + expect(wrapper.html(htmlOptions)).to.contain('span') } ) }) diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index ee399c333..c9b88d00e 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -8,6 +8,8 @@ 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 } @@ -180,8 +182,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => { footer: '

world

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

world

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

world

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

1234

') + expect(ParentComponent.html(htmlOptions)).to.equal('

1234

') }) }) diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 807c3f4e2..39c9ef981 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -13,6 +13,8 @@ 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() @@ -69,7 +71,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html()).to.equal('Hello') + expect(wrapper.html(htmlOptions)).to.equal('Hello') }) it('renders named slots', () => { @@ -88,7 +90,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html()).to.equal( + expect(wrapper.html(htmlOptions)).to.equal( '

Hello

World

' ) }) @@ -99,7 +101,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components: { Child: {} } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.equal('') + expect(wrapper.html(htmlOptions)).to.equal('') }) it('renders children for functional components', () => { @@ -114,7 +116,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html()).to.equal('Hello') + expect(wrapper.html(htmlOptions)).to.equal('Hello') }) it('stubs globally registered components', () => { @@ -170,7 +172,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.contain(' { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.contain(' { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.contain(' { @@ -223,7 +229,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.contain('`, data: () => ({ @@ -232,7 +238,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components } const wrapper2 = shallowMount(TestComponent2) - expect(wrapper2.html()).to.contain('`, data: () => ({ @@ -241,7 +247,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { components } const wrapper3 = shallowMount(TestComponent3) - expect(wrapper3.html()).to.contain(' { @@ -254,7 +260,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { name: 'test-component' } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.contain('') + expect(wrapper.html(htmlOptions)).to.contain('') expect(console.error).not.calledWith('[Vue warn]') }) @@ -421,7 +427,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.equal('') + expect(wrapper.html(htmlOptions)).to.equal( + '' + ) }) it('stubs lazily registered components', () => { @@ -468,7 +476,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { localVue.use(myPlugin) const wrapper = shallowMount(TestComponent, { localVue }) - expect(wrapper.html()).to.contain('registered-component-stub') + expect(wrapper.html(htmlOptions)).to.contain('registered-component-stub') }) it('throws an error when the component fails to mount', () => { @@ -516,7 +524,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { } } const wrapper = shallowMount(TestComponent) - expect(wrapper.html()).to.equal( + expect(wrapper.html(htmlOptions)).to.equal( '
' + ' ' + ' ' + diff --git a/test/specs/wrapper/html.spec.js b/test/specs/wrapper/html.spec.js index ab3c4a005..1ccd3412c 100644 --- a/test/specs/wrapper/html.spec.js +++ b/test/specs/wrapper/html.spec.js @@ -20,7 +20,7 @@ describeWithShallowAndMount('html', mountingMethod => { } } }) - const expectedHtml = '
1
test
' + const expectedHtml = '
1
test
\n' + '
' expect(wrapper.html()).to.equal(expectedHtml) }) @@ -33,14 +33,6 @@ describeWithShallowAndMount('html', mountingMethod => { }) it('returns a Wrappers HTML as a string', () => { - const expectedHtml = - '' - const compiled = compileToFunctions(expectedHtml) - const wrapper = mountingMethod(compiled) - expect(wrapper.html()).to.equal(expectedHtml) - }) - - it('returns a Wrappers HTML as a pretty printed string', () => { const expectedHtml = '\n' + '
\n' + @@ -53,7 +45,15 @@ describeWithShallowAndMount('html', mountingMethod => { const compiled = compileToFunctions(expectedHtml) const wrapper = mountingMethod(compiled) - const options = { prettyPrint: true } + 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) }) })