-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
/
Copy pathdefineAttrs.spec.ts
40 lines (37 loc) · 1002 Bytes
/
defineAttrs.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
import { compileSFCScript as compile, assertCode } from '../utils'
describe('defineAttrs()', () => {
test('basic usage', () => {
const { content } = compile(`
<script setup lang="ts">
const attrs = defineAttrs<{
bar?: number
}>()
</script>
`)
assertCode(content)
expect(content).toMatch(`const attrs = _useAttrs()`)
expect(content).not.toMatch('defineAttrs')
})
test('w/o return value', () => {
const { content } = compile(`
<script setup lang="ts">
defineAttrs<{
bar?: number
}>()
</script>
`)
assertCode(content)
expect(content).not.toMatch('defineAttrs')
expect(content).not.toMatch(`_useAttrs`)
})
test('w/o generic params', () => {
const { content } = compile(`
<script setup>
const attrs = defineAttrs()
</script>
`)
assertCode(content)
expect(content).toMatch(`const attrs = _useAttrs()`)
expect(content).not.toMatch('defineAttrs')
})
})