Skip to content

Commit 58171a8

Browse files
authored
test: test recursive and async component (#8)
1 parent a05fcf7 commit 58171a8

File tree

10 files changed

+137
-0
lines changed

10 files changed

+137
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist
22
node_modules
33
TODOs.md
44
temp
5+
.DS_Store

playground/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TestCustomBlock from './custom/TestCustomBlock.vue'
99
import TestHmr from './hmr/TestHmr.vue'
1010
import TestAssets from './test-assets/TestAssets.vue'
1111
import TestES2020Features from './TestES2020Features.vue'
12+
import TestComponent from './test-component/TestComponent.vue'
1213
import TestCssVBind from './css/TestCssVBind.vue'
1314
</script>
1415

@@ -25,6 +26,7 @@ import TestCssVBind from './css/TestCssVBind.vue'
2526
<TestHmr />
2627
<TestAssets />
2728
<TestES2020Features />
29+
<TestComponent />
2830
<TestCssVBind/>
2931
</div>
3032
</template>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script>
2+
import TestRecursive from './recursive/TestRecursive.vue'
3+
import TestAsyncComponent from './async/TestAsyncComponent.vue'
4+
5+
export default {
6+
name: 'TestRecursion',
7+
components: {
8+
TestRecursive,
9+
TestAsyncComponent
10+
}
11+
}
12+
</script>
13+
14+
<template>
15+
<div>
16+
<h2>Vue Component</h2>
17+
18+
<TestRecursive />
19+
<TestAsyncComponent />
20+
</div>
21+
</template>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<script>
2+
export default {
3+
components: {
4+
componentA: () => import('./componentA.vue')
5+
},
6+
beforeCreate() {
7+
this.$options.components.componentB = () => import('./componentB.vue')
8+
}
9+
}
10+
</script>
11+
12+
<template>
13+
<div>
14+
<h3>Async Component</h3>
15+
<componentA />
16+
<componentB />
17+
18+
<pre>
19+
export default {
20+
components: {
21+
componentA: () => import('./componentA.vue')
22+
},
23+
beforeCreate() {
24+
this.$options.components.componentB = () => import('./componentB.vue')
25+
}
26+
}
27+
</pre>
28+
</div>
29+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<p class="async-component-a">This is componentA</p>
3+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<p class="async-component-b">This is componentB</p>
3+
</template>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script>
2+
import TestRecursiveTree from './TestRecursiveTree.vue'
3+
import treedata from './treedata.json'
4+
5+
export default {
6+
name: 'TestRecursion',
7+
components: {
8+
TestRecursiveTree
9+
},
10+
data() {
11+
return {
12+
treedata: treedata
13+
}
14+
}
15+
}
16+
</script>
17+
18+
<template>
19+
<div>
20+
<h3>Recursive Component</h3>
21+
<TestRecursiveTree :treedata="treedata"></TestRecursiveTree>
22+
</div>
23+
</template>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script>
2+
export default {
3+
name: 'TestRecursiveTree',
4+
props: ['treedata'],
5+
methods: {
6+
isEmpty(data) {
7+
return !data || !data.length
8+
}
9+
}
10+
}
11+
</script>
12+
13+
<template>
14+
<div class="test-recursive-tree">
15+
<div class="test-recursive-item" v-for="item in treedata" :key="item.label">
16+
<h5>{{ item.label }}</h5>
17+
18+
<TestRecursiveTree
19+
v-if="!isEmpty(item.children)"
20+
:treedata="item.children"
21+
>
22+
</TestRecursiveTree>
23+
</div>
24+
</div>
25+
</template>
26+
27+
<style scoped>
28+
.test-recursive-item {
29+
padding-left: 10px;
30+
}
31+
</style>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"label": "name-1",
4+
"children": [
5+
{
6+
"label": "name-1-1",
7+
"children": [
8+
{
9+
"label": "name-1-1-1"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
]

test/test.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ export function declareTests(isBuild: boolean) {
140140
}
141141
})
142142

143+
test('SFC Recursive Component', async () => {
144+
expect(await getText('.test-recursive-item')).toMatch(/name-1-1-1/)
145+
})
146+
147+
test('SFC Async Component', async () => {
148+
expect(await getText('.async-component-a')).toMatch('This is componentA')
149+
expect(await getText('.async-component-b')).toMatch('This is componentB')
150+
})
151+
143152
test('css v-bind', async () => {
144153
const el = await getEl('.css-v-bind')
145154
expect(await getComputedColor(el!)).toBe(`rgb(255, 0, 0)`)

0 commit comments

Comments
 (0)