/
createApp.spec.ts
106 lines (93 loc) · 2.11 KB
/
createApp.spec.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { createApp, defineComponent, ref, nextTick } from '../src'
describe('createApp', () => {
it('should work', async () => {
const app = createApp({
setup() {
return {
a: ref(1),
}
},
template: '<p>{{a}}</p>',
})
const vm = app.mount()
await nextTick()
expect(vm.$el.textContent).toBe('1')
})
it('should work with rootProps', async () => {
const app = createApp(
defineComponent({
props: {
msg: String,
},
template: '<p>{{msg}}</p>',
}),
{
msg: 'foobar',
}
)
const vm = app.mount()
await nextTick()
expect(vm.$el.textContent).toBe('foobar')
})
it('should work with components', async () => {
const Foo = defineComponent({
props: {
msg: {
type: String,
required: true,
},
},
template: '<p>{{msg}}</p>',
})
const app = createApp(
defineComponent({
props: {
msg: String,
},
template: '<Foo :msg="msg"/>',
}),
{
msg: 'foobar',
}
)
app.component('Foo', Foo)
const vm = app.mount()
await nextTick()
expect(vm.$el.textContent).toBe('foobar')
})
it('should work with provide', async () => {
const Foo = defineComponent({
inject: ['msg'],
template: '<p>{{msg}}</p>',
})
const app = createApp(
defineComponent({
template: '<Foo />',
components: { Foo },
})
)
app.provide('msg', 'foobar')
const vm = app.mount()
await nextTick()
expect(vm.$el.textContent).toBe('foobar')
})
it("should respect root component's provide", async () => {
const Foo = defineComponent({
inject: ['msg'],
template: '<p>{{msg}}</p>',
})
const app = createApp(
defineComponent({
template: '<Foo />',
provide: {
msg: 'root component',
},
components: { Foo },
})
)
app.provide('msg', 'application')
const vm = app.mount()
await nextTick()
expect(vm.$el.textContent).toBe('root component')
})
})