Skip to content

Commit a9eda95

Browse files
committed
issue-1146: Make prettyPrint default; update existing tests
1 parent 423690d commit a9eda95

File tree

6 files changed

+62
-50
lines changed

6 files changed

+62
-50
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ export default class Wrapper implements BaseWrapper {
223223
* Returns HTML of element as a string
224224
*/
225225
html(options?: HtmlOptions): string {
226-
if (options && options.prettyPrint) {
227-
return pretty(this.element.outerHTML)
226+
if (options && !options.prettyPrint) {
227+
return this.element.outerHTML
228228
}
229-
return this.element.outerHTML
229+
return pretty(this.element.outerHTML)
230230
}
231231

232232
/**

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ 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-
expect(wrapper.html()).to.equal(
343+
const htmlOptions = { prettyPrint: false }
344+
expect(wrapper.html(htmlOptions)).to.equal(
344345
`<div height="50px" extra="attr"><p class="prop-1">prop1</p> <p class="prop-2"></p></div>`
345346
)
346347
})

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

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

1112
afterEach(() => {
1213
window = windowSave // eslint-disable-line no-native-reassign
@@ -28,7 +29,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
2829
}
2930
}
3031
)
31-
expect(wrapper.html()).to.equal('<div><p>bar,123</p></div>')
32+
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar,123</p></div>')
3233
})
3334

3435
itDoNotRunIf(vueVersion < 2.1, 'handles render functions', () => {
@@ -47,7 +48,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
4748
}
4849
}
4950
)
50-
expect(wrapper.html()).to.equal('<div><p>bar</p></div>')
51+
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar</p></div>')
5152
})
5253

5354
itDoNotRunIf(
@@ -87,7 +88,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
8788
}
8889
}
8990
)
90-
expect(notDestructuringWrapper.html()).to.equal('<p>1,foo</p>')
91+
expect(notDestructuringWrapper.html(htmlOptions)).to.equal('<p>1,foo</p>')
9192
}
9293
)
9394

@@ -112,7 +113,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
112113
}
113114
}
114115
)
115-
expect(destructuringWrapper.html()).to.equal('<p>1,foo</p>')
116+
expect(destructuringWrapper.html(htmlOptions)).to.equal('<p>1,foo</p>')
116117

117118
const notDestructuringWrapper = mountingMethod(
118119
{
@@ -130,7 +131,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
130131
}
131132
}
132133
)
133-
expect(notDestructuringWrapper.html()).to.equal('<p>1,foo</p>')
134+
expect(notDestructuringWrapper.html(htmlOptions)).to.equal('<p>1,foo</p>')
134135
}
135136
)
136137

@@ -145,38 +146,38 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
145146
noProps: '<p slot-scope="baz">baz</p>'
146147
}
147148
})
148-
expect(wrapper.find('#destructuring').html()).to.equal(
149+
expect(wrapper.find('#destructuring').html(htmlOptions)).to.equal(
149150
'<div id="destructuring"><p>0,1</p><p>1,2</p><p>2,3</p></div>'
150151
)
151-
expect(wrapper.find('#slots').html()).to.equal(
152+
expect(wrapper.find('#slots').html(htmlOptions)).to.equal(
152153
'<div id="slots"><span>123</span></div>'
153154
)
154-
expect(wrapper.find('#list').html()).to.equal(
155+
expect(wrapper.find('#list').html(htmlOptions)).to.equal(
155156
'<div id="list"><p>0,a1</p><p>1,a2</p><p>2,a3</p></div>'
156157
)
157-
expect(wrapper.find('#single').html()).to.equal(
158+
expect(wrapper.find('#single').html(htmlOptions)).to.equal(
158159
'<div id="single"><p>abc</p></div>'
159160
)
160-
expect(wrapper.find('#noProps').html()).to.equal(
161+
expect(wrapper.find('#noProps').html(htmlOptions)).to.equal(
161162
'<div id="noProps"><p>baz</p></div>'
162163
)
163164
wrapper.vm.items = [4, 5, 6]
164165
wrapper.vm.foo = [{ text: 'b1' }, { text: 'b2' }, { text: 'b3' }]
165166
wrapper.vm.bar = 'ABC'
166167
await Vue.nextTick()
167-
expect(wrapper.find('#destructuring').html()).to.equal(
168+
expect(wrapper.find('#destructuring').html(htmlOptions)).to.equal(
168169
'<div id="destructuring"><p>0,4</p><p>1,5</p><p>2,6</p></div>'
169170
)
170-
expect(wrapper.find('#slots').html()).to.equal(
171+
expect(wrapper.find('#slots').html(htmlOptions)).to.equal(
171172
'<div id="slots"><span>123</span></div>'
172173
)
173-
expect(wrapper.find('#list').html()).to.equal(
174+
expect(wrapper.find('#list').html(htmlOptions)).to.equal(
174175
'<div id="list"><p>0,b1</p><p>1,b2</p><p>2,b3</p></div>'
175176
)
176-
expect(wrapper.find('#single').html()).to.equal(
177+
expect(wrapper.find('#single').html(htmlOptions)).to.equal(
177178
'<div id="single"><p>ABC</p></div>'
178179
)
179-
expect(wrapper.find('#noProps').html()).to.equal(
180+
expect(wrapper.find('#noProps').html(htmlOptions)).to.equal(
180181
'<div id="noProps"><p>baz</p></div>'
181182
)
182183
})
@@ -197,7 +198,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
197198
}
198199
}
199200
)
200-
expect(wrapper.html()).to.equal('<div><p>bar</p></div>')
201+
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar</p></div>')
201202
})
202203

203204
itDoNotRunIf(vueVersion < 2.5, 'handles no slot-scope', () => {
@@ -214,7 +215,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
214215
}
215216
}
216217
)
217-
expect(wrapper.html()).to.equal('<div><p>bar,123</p></div>')
218+
expect(wrapper.html(htmlOptions)).to.equal('<div><p>bar,123</p></div>')
218219
})
219220

220221
itDoNotRunIf(
@@ -286,7 +287,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
286287
localVue
287288
})
288289

289-
expect(wrapper.html()).to.contain('span')
290+
expect(wrapper.html(htmlOptions)).to.contain('span')
290291
}
291292
)
292293
})

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ 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+
1113
it('mounts component with default slot if passed component in slot object', () => {
1214
const wrapper = mountingMethod(ComponentWithSlots, {
1315
slots: { default: Component }
@@ -180,8 +182,8 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
180182
footer: '<p>world</p>'
181183
}
182184
})
183-
expect(wrapper.html()).to.contain('<span>hello</span>')
184-
expect(wrapper.html()).to.contain('<p>world</p>')
185+
expect(wrapper.html(htmlOptions)).to.contain('<span>hello</span>')
186+
expect(wrapper.html(htmlOptions)).to.contain('<p>world</p>')
185187
})
186188

187189
it('mounts component with default and named text slot', () => {
@@ -496,7 +498,7 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
496498
c => c.$options.name === childComponentName
497499
)
498500
).to.equal(true)
499-
expect(ParentComponent.html()).to.equal(
501+
expect(ParentComponent.html(htmlOptions)).to.equal(
500502
'<div><div><span baz="qux">FOO,quux</span></div><div><span baz="qux">FOO,quux</span></div></div>'
501503
)
502504

@@ -529,6 +531,6 @@ describeWithShallowAndMount('options.slots', mountingMethod => {
529531
c => c.$options.name === childComponentName
530532
)
531533
).to.equal(true)
532-
expect(ParentComponent.html()).to.equal('<div><p>1234</p></div>')
534+
expect(ParentComponent.html(htmlOptions)).to.equal('<div><p>1234</p></div>')
533535
})
534536
})

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

+22-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ 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+
1618
beforeEach(() => {
1719
sandbox.stub(console, 'info').callThrough()
1820
sandbox.stub(console, 'error').callThrough()
@@ -69,7 +71,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
6971
const wrapper = shallowMount(TestComponent, {
7072
localVue
7173
})
72-
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
74+
expect(wrapper.html(htmlOptions)).to.equal('<child-stub>Hello</child-stub>')
7375
})
7476

7577
it('renders named slots', () => {
@@ -88,7 +90,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
8890
const wrapper = shallowMount(TestComponent, {
8991
localVue
9092
})
91-
expect(wrapper.html()).to.equal(
93+
expect(wrapper.html(htmlOptions)).to.equal(
9294
'<child-stub><p>Hello</p> <p>World</p></child-stub>'
9395
)
9496
})
@@ -99,7 +101,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
99101
components: { Child: {} }
100102
}
101103
const wrapper = shallowMount(TestComponent)
102-
expect(wrapper.html()).to.equal('<child-stub></child-stub>')
104+
expect(wrapper.html(htmlOptions)).to.equal('<child-stub></child-stub>')
103105
})
104106

105107
it('renders children for functional components', () => {
@@ -114,7 +116,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
114116
const wrapper = shallowMount(TestComponent, {
115117
localVue
116118
})
117-
expect(wrapper.html()).to.equal('<child-stub>Hello</child-stub>')
119+
expect(wrapper.html(htmlOptions)).to.equal('<child-stub>Hello</child-stub>')
118120
})
119121

120122
it('stubs globally registered components', () => {
@@ -170,7 +172,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
170172
}
171173
}
172174
const wrapper = shallowMount(TestComponent)
173-
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
175+
expect(wrapper.html(htmlOptions)).to.contain(
176+
'<child-stub prop="a" attr="hello"'
177+
)
174178
}
175179
)
176180

@@ -188,7 +192,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
188192
}
189193
}
190194
const wrapper = shallowMount(TestComponent)
191-
expect(wrapper.html()).to.contain('<child-stub class="b a"')
195+
expect(wrapper.html(htmlOptions)).to.contain('<child-stub class="b a"')
192196
}
193197
)
194198

@@ -206,7 +210,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
206210
}
207211
}
208212
const wrapper = shallowMount(TestComponent)
209-
expect(wrapper.html()).to.contain('<child-stub prop="a" attr="hello"')
213+
expect(wrapper.html(htmlOptions)).to.contain(
214+
'<child-stub prop="a" attr="hello"'
215+
)
210216
})
211217

212218
it('renders classes for functional components', () => {
@@ -223,7 +229,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
223229
components
224230
}
225231
const wrapper = shallowMount(TestComponent)
226-
expect(wrapper.html()).to.contain('<child-stub class="b a"')
232+
expect(wrapper.html(htmlOptions)).to.contain('<child-stub class="b a"')
227233
const TestComponent2 = {
228234
template: `<child :class="classA"/>`,
229235
data: () => ({
@@ -232,7 +238,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
232238
components
233239
}
234240
const wrapper2 = shallowMount(TestComponent2)
235-
expect(wrapper2.html()).to.contain('<child-stub class="a"')
241+
expect(wrapper2.html(htmlOptions)).to.contain('<child-stub class="a"')
236242
const TestComponent3 = {
237243
template: `<child class="b" />`,
238244
data: () => ({
@@ -241,7 +247,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
241247
components
242248
}
243249
const wrapper3 = shallowMount(TestComponent3)
244-
expect(wrapper3.html()).to.contain('<child-stub class="b"')
250+
expect(wrapper3.html(htmlOptions)).to.contain('<child-stub class="b"')
245251
})
246252

247253
itDoNotRunIf(vueVersion < 2.1, 'handles recursive components', () => {
@@ -254,7 +260,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
254260
name: 'test-component'
255261
}
256262
const wrapper = shallowMount(TestComponent)
257-
expect(wrapper.html()).to.contain('<test-component-stub>')
263+
expect(wrapper.html(htmlOptions)).to.contain('<test-component-stub>')
258264
expect(console.error).not.calledWith('[Vue warn]')
259265
})
260266

@@ -421,7 +427,9 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
421427
}
422428
const wrapper = shallowMount(TestComponent)
423429

424-
expect(wrapper.html()).to.equal('<custom-element></custom-element>')
430+
expect(wrapper.html(htmlOptions)).to.equal(
431+
'<custom-element></custom-element>'
432+
)
425433
})
426434

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

469477
localVue.use(myPlugin)
470478
const wrapper = shallowMount(TestComponent, { localVue })
471-
expect(wrapper.html()).to.contain('registered-component-stub')
479+
expect(wrapper.html(htmlOptions)).to.contain('registered-component-stub')
472480
})
473481

474482
it('throws an error when the component fails to mount', () => {
@@ -516,7 +524,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
516524
}
517525
}
518526
const wrapper = shallowMount(TestComponent)
519-
expect(wrapper.html()).to.equal(
527+
expect(wrapper.html(htmlOptions)).to.equal(
520528
'<div>' +
521529
'<childcomponent-stub></childcomponent-stub> ' +
522530
'<anonymous-stub></anonymous-stub> ' +

Diff for: test/specs/wrapper/html.spec.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describeWithShallowAndMount('html', mountingMethod => {
2020
}
2121
}
2222
})
23-
const expectedHtml = '<div>1<div class="tester">test</div></div>'
23+
const expectedHtml = '<div>1<div class="tester">test</div>\n' + '</div>'
2424
expect(wrapper.html()).to.equal(expectedHtml)
2525
})
2626

@@ -33,14 +33,6 @@ describeWithShallowAndMount('html', mountingMethod => {
3333
})
3434

3535
it('returns a Wrappers HTML as a string', () => {
36-
const expectedHtml =
37-
'<input id="input-submit" type="submit" class="input-submit">'
38-
const compiled = compileToFunctions(expectedHtml)
39-
const wrapper = mountingMethod(compiled)
40-
expect(wrapper.html()).to.equal(expectedHtml)
41-
})
42-
43-
it('returns a Wrappers HTML as a pretty printed string', () => {
4436
const expectedHtml =
4537
'<body>\n' +
4638
' <div>\n' +
@@ -53,7 +45,15 @@ describeWithShallowAndMount('html', mountingMethod => {
5345

5446
const compiled = compileToFunctions(expectedHtml)
5547
const wrapper = mountingMethod(compiled)
56-
const options = { prettyPrint: true }
48+
expect(wrapper.html()).to.equal(expectedHtml)
49+
})
50+
51+
it('returns a Wrappers HTML not as a pretty printed string', () => {
52+
const expectedHtml = '<body><div><ul><li></li><li></li></ul></div></body>'
53+
54+
const compiled = compileToFunctions(expectedHtml)
55+
const wrapper = mountingMethod(compiled)
56+
const options = { prettyPrint: false }
5757
expect(wrapper.html(options)).to.equal(expectedHtml)
5858
})
5959
})

0 commit comments

Comments
 (0)