forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml.spec.js
59 lines (53 loc) · 1.93 KB
/
html.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { compileToFunctions } from 'vue-template-compiler'
import Component from '~resources/components/component.vue'
import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
import { vueVersion, describeWithShallowAndMount } from '~resources/utils'
describeWithShallowAndMount('html', mountingMethod => {
it('returns a VueWrappers HTML as a string', () => {
const expectedHtml = '<div></div>'
const wrapper = mountingMethod(Component)
expect(wrapper.html()).to.equal(expectedHtml)
})
it('returns a VueWrappers HTML as a string when component has no render function', () => {
if (mountingMethod.name === 'shallowMount') return
const wrapper = mountingMethod({
template: `<div>1<tester></tester></div>`,
components: {
tester: {
template: `<div class="tester">test</div>`
}
}
})
const expectedHtml = '<div>1<div class="tester">test</div></div>'
expect(wrapper.html()).to.equal(expectedHtml)
})
it('handles class component', () => {
if (vueVersion < 2.3) {
return
}
const wrapper = mountingMethod(ComponentAsAClass)
expect(wrapper.html()).to.equal('<div></div>')
})
it('returns a Wrappers HTML as a string', () => {
const expectedHtml =
'<input id="input-submit" type="submit" class="input-submit">'
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 =
'<body>\n' +
' <div>\n' +
' <ul>\n' +
' <li></li>\n' +
' <li></li>\n' +
' </ul>\n' +
' </div>\n' +
'</body>'
const compiled = compileToFunctions(expectedHtml)
const wrapper = mountingMethod(compiled)
const options = { prettyPrint: true }
expect(wrapper.html(options)).to.equal(expectedHtml)
})
})