-
Notifications
You must be signed in to change notification settings - Fork 433
/
Copy pathjsx.tsx
87 lines (69 loc) · 1.88 KB
/
jsx.tsx
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
import { PropType } from 'vue'
import { Vue, prop } from '../src'
describe('JSX', () => {
function assertJsx(jsx: JSX.Element): void {}
it('checks props type', () => {
interface Person {
name: string
age?: number
}
class Props {
required!: string
optional?: number
withDefault = prop({ default: false })
withDefaultType = prop<Person>({
default: () => ({
name: 'Test',
age: 20,
}),
})
}
class App extends Vue.props(Props) {}
assertJsx(<App required="Hello" />)
assertJsx(
<App
required="Hello"
optional={123}
withDefault={true}
withDefaultType={{ name: 'Foo' }}
/>
)
// @ts-expect-error
assertJsx(<App />)
// @ts-expect-error
assertJsx(<App required={true} />)
// @ts-expect-error
assertJsx(<App required="Hello" optional={{ foo: 'bar' }} />)
// @ts-expect-error
assertJsx(<App required="Hello" withDefault={Symbol()} />)
assertJsx(
// @ts-expect-error
<App required="Hello" withDefaultType={{ name: 'Foo', age: true }} />
)
assertJsx(
<App ref="app" class="foo" required="Test" testCustomProp="custom" />
)
})
it('passes vnode props', () => {
class App extends Vue {}
assertJsx(<App ref="test" />)
assertJsx(<App key="123" />)
})
it('passes class and style attributes', () => {
class App extends Vue {}
assertJsx(<App class="foo" />)
assertJsx(<App class={{ disabled: true }} />)
assertJsx(<App class={['test']} />)
assertJsx(<App style="font-size: 12px;" />)
assertJsx(<App style={{ color: 'red' }} />)
})
it('passes component custom props', () => {
class App extends Vue {}
assertJsx(<App testCustomProp="test" />)
})
})
declare module '@vue/runtime-core' {
interface ComponentCustomProps {
testCustomProp?: string
}
}