Skip to content

Commit 72f10fb

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

File tree

7 files changed

+83
-80
lines changed

7 files changed

+83
-80
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

+10-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,11 @@ 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+
expect(ParentComponent.html()).to.equal(
500+
'<div>\n' +
501+
' <div><span baz="qux">FOO,quux</span></div>\n' +
502+
' <div><span baz="qux">FOO,quux</span></div>\n' +
503+
'</div>'
503504
)
504505

505506
ParentComponent = mount(
@@ -531,6 +532,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
531532
c => c.$options.name === childComponentName
532533
)
533534
).to.equal(true)
534-
expect(ParentComponent.html(htmlOptions)).to.equal('<div><p>1234</p></div>')
535+
expect(ParentComponent.html()).to.equal(
536+
'<div>\n' + ' <p>1234</p>\n' + '</div>'
537+
)
535538
})
536539
})

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

+23-28
Original file line numberDiff line numberDiff line change
@@ -13,8 +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 }
17-
1816
beforeEach(() => {
1917
sandbox.stub(console, 'info').callThrough()
2018
sandbox.stub(console, 'error').callThrough()
@@ -71,7 +69,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
7169
const wrapper = shallowMount(TestComponent, {
7270
localVue
7371
})
74-
expect(wrapper.html(htmlOptions)).to.equal('<child-stub>Hello</child-stub>')
72+
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
7573
})
7674

7775
it('renders named slots', () => {
@@ -90,8 +88,11 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
9088
const wrapper = shallowMount(TestComponent, {
9189
localVue
9290
})
93-
expect(wrapper.html(htmlOptions)).to.equal(
94-
'<child-stub><p>Hello</p> <p>World</p></child-stub>'
91+
expect(wrapper.html()).to.equal(
92+
'<child-stub>\n' +
93+
' <p>Hello</p>\n' +
94+
' <p>World</p>\n' +
95+
'</child-stub>'
9596
)
9697
})
9798

@@ -101,7 +102,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
101102
components: { Child: {} }
102103
}
103104
const wrapper = shallowMount(TestComponent)
104-
expect(wrapper.html(htmlOptions)).to.equal('<child-stub></child-stub>')
105+
expect(wrapper.html()).to.equal('<child-stub></child-stub>')
105106
})
106107

107108
it('renders children for functional components', () => {
@@ -116,7 +117,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
116117
const wrapper = shallowMount(TestComponent, {
117118
localVue
118119
})
119-
expect(wrapper.html(htmlOptions)).to.equal('<child-stub>Hello</child-stub>')
120+
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
120121
})
121122

122123
it('stubs globally registered components', () => {
@@ -172,9 +173,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
172173
}
173174
}
174175
const wrapper = shallowMount(TestComponent)
175-
expect(wrapper.html(htmlOptions)).to.contain(
176-
'<child-stub prop="a" attr="hello"'
177-
)
176+
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
178177
}
179178
)
180179

@@ -192,7 +191,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
192191
}
193192
}
194193
const wrapper = shallowMount(TestComponent)
195-
expect(wrapper.html(htmlOptions)).to.contain('<child-stub class="b a"')
194+
expect(wrapper.html()).to.contain('<child-stub class="b a"')
196195
}
197196
)
198197

@@ -210,9 +209,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
210209
}
211210
}
212211
const wrapper = shallowMount(TestComponent)
213-
expect(wrapper.html(htmlOptions)).to.contain(
214-
'<child-stub prop="a" attr="hello"'
215-
)
212+
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
216213
})
217214

218215
it('renders classes for functional components', () => {
@@ -229,7 +226,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
229226
components
230227
}
231228
const wrapper = shallowMount(TestComponent)
232-
expect(wrapper.html(htmlOptions)).to.contain('<child-stub class="b a"')
229+
expect(wrapper.html()).to.contain('<child-stub class="b a"')
233230
const TestComponent2 = {
234231
template: `<child :class="classA"/>`,
235232
data: () => ({
@@ -238,7 +235,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
238235
components
239236
}
240237
const wrapper2 = shallowMount(TestComponent2)
241-
expect(wrapper2.html(htmlOptions)).to.contain('<child-stub class="a"')
238+
expect(wrapper2.html()).to.contain('<child-stub class="a"')
242239
const TestComponent3 = {
243240
template: `<child class="b" />`,
244241
data: () => ({
@@ -247,7 +244,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
247244
components
248245
}
249246
const wrapper3 = shallowMount(TestComponent3)
250-
expect(wrapper3.html(htmlOptions)).to.contain('<child-stub class="b"')
247+
expect(wrapper3.html()).to.contain('<child-stub class="b"')
251248
})
252249

253250
itDoNotRunIf(vueVersion < 2.1, 'handles recursive components', () => {
@@ -260,7 +257,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
260257
name: 'test-component'
261258
}
262259
const wrapper = shallowMount(TestComponent)
263-
expect(wrapper.html(htmlOptions)).to.contain('<test-component-stub>')
260+
expect(wrapper.html()).to.contain('<test-component-stub>')
264261
expect(console.error).not.calledWith('[Vue warn]')
265262
})
266263

@@ -427,9 +424,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
427424
}
428425
const wrapper = shallowMount(TestComponent)
429426

430-
expect(wrapper.html(htmlOptions)).to.equal(
431-
'<custom-element></custom-element>'
432-
)
427+
expect(wrapper.html()).to.equal('<custom-element></custom-element>')
433428
})
434429

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

477472
localVue.use(myPlugin)
478473
const wrapper = shallowMount(TestComponent, { localVue })
479-
expect(wrapper.html(htmlOptions)).to.contain('registered-component-stub')
474+
expect(wrapper.html()).to.contain('registered-component-stub')
480475
})
481476

482477
it('throws an error when the component fails to mount', () => {
@@ -524,12 +519,12 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
524519
}
525520
}
526521
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>' +
522+
expect(wrapper.html()).to.equal(
523+
'<div>\n' +
524+
' <childcomponent-stub></childcomponent-stub>\n' +
525+
' <anonymous-stub></anonymous-stub>\n' +
526+
' <anonymous-stub></anonymous-stub>\n' +
527+
' <anonymous-stub></anonymous-stub>\n' +
533528
'</div>'
534529
)
535530
})

0 commit comments

Comments
 (0)