forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisEmpty.spec.js
65 lines (56 loc) · 1.86 KB
/
isEmpty.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
60
61
62
63
64
65
import { compileToFunctions } from 'vue-template-compiler'
import {
describeWithShallowAndMount,
isRunningPhantomJS
} from '~resources/utils'
import { itSkipIf } from 'conditional-specs'
describeWithShallowAndMount('isEmpty', (mountingMethod) => {
it('returns true if node is empty', () => {
const compiled = compileToFunctions('<div></div>')
const wrapper = mountingMethod(compiled)
expect(wrapper.isEmpty()).to.equal(true)
})
it('returns true if node contains comment', () => {
const compiled = compileToFunctions('<div><div v-if="false"></div></div>')
const wrapper = mountingMethod(compiled)
expect(wrapper.isEmpty()).to.equal(true)
})
itSkipIf(
isRunningPhantomJS,
'returns true if innerHTML is empty', () => {
const TestComponent = {
render (createElement) {
return createElement('div', {
domProps: {
innerHTML: '<svg />'
}
})
}
}
const wrapper = mountingMethod(TestComponent)
expect(wrapper.find('svg').isEmpty()).to.equal(true)
})
it.skip('returns false if innerHTML is not empty', () => {
const TestComponent = {
render (createElement) {
return createElement('div', {
domProps: {
innerHTML: '<svg><p>not empty</p></svg>'
}
})
}
}
const wrapper = mountingMethod(TestComponent)
expect(wrapper.find('svg').isEmpty()).to.equal(false)
})
it('returns true contains empty slot', () => {
const compiled = compileToFunctions('<div><slot></slot></div>')
const wrapper = mountingMethod(compiled)
expect(wrapper.isEmpty()).to.equal(true)
})
it('returns false if node contains other nodes', () => {
const compiled = compileToFunctions('<div><p /></div>')
const wrapper = mountingMethod(compiled)
expect(wrapper.isEmpty()).to.equal(false)
})
})