Skip to content

Commit 4a5bfac

Browse files
committed
issue-1146: updated so that pretty printing html is default
1 parent a9eda95 commit 4a5bfac

File tree

7 files changed

+84
-79
lines changed

7 files changed

+84
-79
lines changed

Diff for: flow/wrapper.flow.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type WrapperArray from '~src/WrapperArray'
55

66
declare type Selector = any
77
declare type Components = { [name: string]: Component }
8-
declare type HtmlOptions = { prettyPrint: boolean }
98

109
declare interface BaseWrapper {
1110
// eslint-disable-line no-undef

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ export default class Wrapper implements BaseWrapper {
222222
/**
223223
* Returns HTML of element as a string
224224
*/
225-
html(options?: HtmlOptions): string {
226-
if (options && !options.prettyPrint) {
227-
return this.element.outerHTML
228-
}
225+
html(): string {
229226
return pretty(this.element.outerHTML)
230227
}
231228

Diff for: test/specs/mount.spec.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,12 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
340340
if (vueVersion > 2.3) {
341341
expect(wrapper.vm.$attrs).to.eql({ height: '50px', extra: 'attr' })
342342
}
343-
const htmlOptions = { prettyPrint: false }
344-
expect(wrapper.html(htmlOptions)).to.equal(
345-
`<div height="50px" extra="attr"><p class="prop-1">prop1</p> <p class="prop-2"></p></div>`
343+
344+
expect(wrapper.html()).to.equal(
345+
'<div height="50px" extra="attr">\n' +
346+
' <p class="prop-1">prop1</p>\n' +
347+
' <p class="prop-2"></p>\n' +
348+
'</div>'
346349
)
347350
})
348351

Diff for: test/specs/mounting-options/scopedSlots.spec.js

+42-27
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import Vue from 'vue'
77
describeWithShallowAndMount('scopedSlots', mountingMethod => {
88
const sandbox = sinon.createSandbox()
99
const windowSave = window
10-
const htmlOptions = { prettyPrint: false }
1110

1211
afterEach(() => {
1312
window = windowSave // eslint-disable-line no-native-reassign
@@ -29,7 +28,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
2928
}
3029
}
3130
)
32-
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar,123</p></div>')
31+
expect(wrapper.html()).to.equal('<div>\n' + ' <p>bar,123</p>\n' + '</div>')
3332
})
3433

3534
itDoNotRunIf(vueVersion < 2.1, 'handles render functions', () => {
@@ -48,7 +47,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
4847
}
4948
}
5049
)
51-
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar</p></div>')
50+
expect(wrapper.html()).to.equal('<div>\n' + ' <p>bar</p>\n' + '</div>')
5251
})
5352

5453
itDoNotRunIf(
@@ -88,7 +87,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
8887
}
8988
}
9089
)
91-
expect(notDestructuringWrapper.html(htmlOptions)).to.equal('<p>1,foo</p>')
90+
expect(notDestructuringWrapper.html()).to.equal('<p>1,foo</p>')
9291
}
9392
)
9493

@@ -113,7 +112,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
113112
}
114113
}
115114
)
116-
expect(destructuringWrapper.html(htmlOptions)).to.equal('<p>1,foo</p>')
115+
expect(destructuringWrapper.html()).to.equal('<p>1,foo</p>')
117116

118117
const notDestructuringWrapper = mountingMethod(
119118
{
@@ -131,7 +130,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
131130
}
132131
}
133132
)
134-
expect(notDestructuringWrapper.html(htmlOptions)).to.equal('<p>1,foo</p>')
133+
expect(notDestructuringWrapper.html()).to.equal('<p>1,foo</p>')
135134
}
136135
)
137136

@@ -146,39 +145,55 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
146145
noProps: '<p slot-scope="baz">baz</p>'
147146
}
148147
})
149-
expect(wrapper.find('#destructuring').html(htmlOptions)).to.equal(
150-
'<div id="destructuring"><p>0,1</p><p>1,2</p><p>2,3</p></div>'
148+
expect(wrapper.find('#destructuring').html()).to.equal(
149+
'<div id="destructuring">\n' +
150+
' <p>0,1</p>\n' +
151+
' <p>1,2</p>\n' +
152+
' <p>2,3</p>\n' +
153+
'</div>'
151154
)
152-
expect(wrapper.find('#slots').html(htmlOptions)).to.equal(
155+
expect(wrapper.find('#slots').html()).to.equal(
153156
'<div id="slots"><span>123</span></div>'
154157
)
155-
expect(wrapper.find('#list').html(htmlOptions)).to.equal(
156-
'<div id="list"><p>0,a1</p><p>1,a2</p><p>2,a3</p></div>'
158+
expect(wrapper.find('#list').html()).to.equal(
159+
'<div id="list">\n' +
160+
' <p>0,a1</p>\n' +
161+
' <p>1,a2</p>\n' +
162+
' <p>2,a3</p>\n' +
163+
'</div>'
157164
)
158-
expect(wrapper.find('#single').html(htmlOptions)).to.equal(
159-
'<div id="single"><p>abc</p></div>'
165+
expect(wrapper.find('#single').html()).to.equal(
166+
'<div id="single">\n' + ' <p>abc</p>\n' + '</div>'
160167
)
161-
expect(wrapper.find('#noProps').html(htmlOptions)).to.equal(
162-
'<div id="noProps"><p>baz</p></div>'
168+
expect(wrapper.find('#noProps').html()).to.equal(
169+
'<div id="noProps">\n' + ' <p>baz</p>\n' + '</div>'
163170
)
164171
wrapper.vm.items = [4, 5, 6]
165172
wrapper.vm.foo = [{ text: 'b1' }, { text: 'b2' }, { text: 'b3' }]
166173
wrapper.vm.bar = 'ABC'
167174
await Vue.nextTick()
168-
expect(wrapper.find('#destructuring').html(htmlOptions)).to.equal(
169-
'<div id="destructuring"><p>0,4</p><p>1,5</p><p>2,6</p></div>'
175+
expect(wrapper.find('#destructuring').html()).to.equal(
176+
'<div id="destructuring">\n' +
177+
' <p>0,4</p>\n' +
178+
' <p>1,5</p>\n' +
179+
' <p>2,6</p>\n' +
180+
'</div>'
170181
)
171-
expect(wrapper.find('#slots').html(htmlOptions)).to.equal(
182+
expect(wrapper.find('#slots').html()).to.equal(
172183
'<div id="slots"><span>123</span></div>'
173184
)
174-
expect(wrapper.find('#list').html(htmlOptions)).to.equal(
175-
'<div id="list"><p>0,b1</p><p>1,b2</p><p>2,b3</p></div>'
185+
expect(wrapper.find('#list').html()).to.equal(
186+
'<div id="list">\n' +
187+
' <p>0,b1</p>\n' +
188+
' <p>1,b2</p>\n' +
189+
' <p>2,b3</p>\n' +
190+
'</div>'
176191
)
177-
expect(wrapper.find('#single').html(htmlOptions)).to.equal(
178-
'<div id="single"><p>ABC</p></div>'
192+
expect(wrapper.find('#single').html()).to.equal(
193+
'<div id="single">\n' + ' <p>ABC</p>\n' + '</div>'
179194
)
180-
expect(wrapper.find('#noProps').html(htmlOptions)).to.equal(
181-
'<div id="noProps"><p>baz</p></div>'
195+
expect(wrapper.find('#noProps').html()).to.equal(
196+
'<div id="noProps">\n' + ' <p>baz</p>\n' + '</div>'
182197
)
183198
})
184199

@@ -198,7 +213,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
198213
}
199214
}
200215
)
201-
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar</p></div>')
216+
expect(wrapper.html()).to.equal('<div>\n' + ' <p>bar</p>\n' + '</div>')
202217
})
203218

204219
itDoNotRunIf(vueVersion < 2.5, 'handles no slot-scope', () => {
@@ -215,7 +230,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
215230
}
216231
}
217232
)
218-
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar,123</p></div>')
233+
expect(wrapper.html()).to.equal('<div>\n' + ' <p>bar,123</p>\n' + '</div>')
219234
})
220235

221236
itDoNotRunIf(
@@ -287,7 +302,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
287302
localVue
288303
})
289304

290-
expect(wrapper.html(htmlOptions)).to.contain('span')
305+
expect(wrapper.html()).to.contain('span')
291306
}
292307
)
293308
})

Diff for: test/specs/mounting-options/slots.spec.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { itDoNotRunIf } from 'conditional-specs'
88
import { mount, createLocalVue } from '~vue/test-utils'
99

1010
describeWithShallowAndMount('options.slots', mountingMethod => {
11-
const htmlOptions = { prettyPrint: false }
12-
1311
it('mounts component with default slot if passed component in slot object', () => {
1412
const wrapper = mountingMethod(ComponentWithSlots, {
1513
slots: { default: Component }
@@ -182,8 +180,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
182180
footer: '<p>world</p>'
183181
}
184182
})
185-
expect(wrapper.html(htmlOptions)).to.contain('<span>hello</span>')
186-
expect(wrapper.html(htmlOptions)).to.contain('<p>world</p>')
183+
expect(wrapper.html()).to.contain('<span>hello</span>')
184+
expect(wrapper.html()).to.contain('<p>world</p>')
187185
})
188186

189187
it('mounts component with default and named text slot', () => {
@@ -498,8 +496,12 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
498496
c => c.$options.name === childComponentName
499497
)
500498
).to.equal(true)
501-
expect(ParentComponent.html(htmlOptions)).to.equal(
502-
'<div><div><span baz="qux">FOO,quux</span></div><div><span baz="qux">FOO,quux</span></div></div>'
499+
500+
expect(ParentComponent.html()).to.equal(
501+
'<div>\n' +
502+
' <div><span baz="qux">FOO,quux</span></div>\n' +
503+
' <div><span baz="qux">FOO,quux</span></div>\n' +
504+
'</div>'
503505
)
504506

505507
ParentComponent = mount(
@@ -531,6 +533,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
531533
c => c.$options.name === childComponentName
532534
)
533535
).to.equal(true)
534-
expect(ParentComponent.html(htmlOptions)).to.equal('<div><p>1234</p></div>')
536+
expect(ParentComponent.html()).to.equal(
537+
'<div>\n' + ' <p>1234</p>\n' + '</div>'
538+
)
535539
})
536540
})

Diff for: test/specs/shallow-mount.spec.js

+23-27
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { describeRunIf, itDoNotRunIf } from 'conditional-specs'
1313

1414
describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
1515
const sandbox = sinon.createSandbox()
16-
const htmlOptions = { prettyPrint: false }
1716

1817
beforeEach(() => {
1918
sandbox.stub(console, 'info').callThrough()
@@ -71,7 +70,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
7170
const wrapper = shallowMount(TestComponent, {
7271
localVue
7372
})
74-
expect(wrapper.html(htmlOptions)).to.equal('<child-stub>Hello</child-stub>')
73+
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
7574
})
7675

7776
it('renders named slots', () => {
@@ -90,8 +89,11 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
9089
const wrapper = shallowMount(TestComponent, {
9190
localVue
9291
})
93-
expect(wrapper.html(htmlOptions)).to.equal(
94-
'<child-stub><p>Hello</p> <p>World</p></child-stub>'
92+
expect(wrapper.html()).to.equal(
93+
'<child-stub>\n' +
94+
' <p>Hello</p>\n' +
95+
' <p>World</p>\n' +
96+
'</child-stub>'
9597
)
9698
})
9799

@@ -101,7 +103,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
101103
components: { Child: {} }
102104
}
103105
const wrapper = shallowMount(TestComponent)
104-
expect(wrapper.html(htmlOptions)).to.equal('<child-stub></child-stub>')
106+
expect(wrapper.html()).to.equal('<child-stub></child-stub>')
105107
})
106108

107109
it('renders children for functional components', () => {
@@ -116,7 +118,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
116118
const wrapper = shallowMount(TestComponent, {
117119
localVue
118120
})
119-
expect(wrapper.html(htmlOptions)).to.equal('<child-stub>Hello</child-stub>')
121+
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
120122
})
121123

122124
it('stubs globally registered components', () => {
@@ -172,9 +174,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
172174
}
173175
}
174176
const wrapper = shallowMount(TestComponent)
175-
expect(wrapper.html(htmlOptions)).to.contain(
176-
'<child-stub prop="a" attr="hello"'
177-
)
177+
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
178178
}
179179
)
180180

@@ -192,7 +192,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
192192
}
193193
}
194194
const wrapper = shallowMount(TestComponent)
195-
expect(wrapper.html(htmlOptions)).to.contain('<child-stub class="b a"')
195+
expect(wrapper.html()).to.contain('<child-stub class="b a"')
196196
}
197197
)
198198

@@ -210,9 +210,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
210210
}
211211
}
212212
const wrapper = shallowMount(TestComponent)
213-
expect(wrapper.html(htmlOptions)).to.contain(
214-
'<child-stub prop="a" attr="hello"'
215-
)
213+
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
216214
})
217215

218216
it('renders classes for functional components', () => {
@@ -229,7 +227,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
229227
components
230228
}
231229
const wrapper = shallowMount(TestComponent)
232-
expect(wrapper.html(htmlOptions)).to.contain('<child-stub class="b a"')
230+
expect(wrapper.html()).to.contain('<child-stub class="b a"')
233231
const TestComponent2 = {
234232
template: `<child :class="classA"/>`,
235233
data: () => ({
@@ -238,7 +236,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
238236
components
239237
}
240238
const wrapper2 = shallowMount(TestComponent2)
241-
expect(wrapper2.html(htmlOptions)).to.contain('<child-stub class="a"')
239+
expect(wrapper2.html()).to.contain('<child-stub class="a"')
242240
const TestComponent3 = {
243241
template: `<child class="b" />`,
244242
data: () => ({
@@ -247,7 +245,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
247245
components
248246
}
249247
const wrapper3 = shallowMount(TestComponent3)
250-
expect(wrapper3.html(htmlOptions)).to.contain('<child-stub class="b"')
248+
expect(wrapper3.html()).to.contain('<child-stub class="b"')
251249
})
252250

253251
itDoNotRunIf(vueVersion < 2.1, 'handles recursive components', () => {
@@ -260,7 +258,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
260258
name: 'test-component'
261259
}
262260
const wrapper = shallowMount(TestComponent)
263-
expect(wrapper.html(htmlOptions)).to.contain('<test-component-stub>')
261+
expect(wrapper.html()).to.contain('<test-component-stub>')
264262
expect(console.error).not.calledWith('[Vue warn]')
265263
})
266264

@@ -427,9 +425,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
427425
}
428426
const wrapper = shallowMount(TestComponent)
429427

430-
expect(wrapper.html(htmlOptions)).to.equal(
431-
'<custom-element></custom-element>'
432-
)
428+
expect(wrapper.html()).to.equal('<custom-element></custom-element>')
433429
})
434430

435431
it('stubs lazily registered components', () => {
@@ -476,7 +472,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
476472

477473
localVue.use(myPlugin)
478474
const wrapper = shallowMount(TestComponent, { localVue })
479-
expect(wrapper.html(htmlOptions)).to.contain('registered-component-stub')
475+
expect(wrapper.html()).to.contain('registered-component-stub')
480476
})
481477

482478
it('throws an error when the component fails to mount', () => {
@@ -524,12 +520,12 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
524520
}
525521
}
526522
const wrapper = shallowMount(TestComponent)
527-
expect(wrapper.html(htmlOptions)).to.equal(
528-
'<div>' +
529-
'<childcomponent-stub></childcomponent-stub> ' +
530-
'<anonymous-stub></anonymous-stub> ' +
531-
'<anonymous-stub></anonymous-stub> ' +
532-
'<anonymous-stub></anonymous-stub>' +
523+
expect(wrapper.html()).to.equal(
524+
'<div>\n' +
525+
' <childcomponent-stub></childcomponent-stub>\n' +
526+
' <anonymous-stub></anonymous-stub>\n' +
527+
' <anonymous-stub></anonymous-stub>\n' +
528+
' <anonymous-stub></anonymous-stub>\n' +
533529
'</div>'
534530
)
535531
})

0 commit comments

Comments
 (0)