-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathprops.test.ts
More file actions
65 lines (56 loc) · 1.58 KB
/
Copy pathprops.test.ts
File metadata and controls
65 lines (56 loc) · 1.58 KB
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 { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { rmSync } from 'node:fs'
import { render } from '../../render/index.ts'
import { createTempProject } from './_helpers.ts'
describe('render props', () => {
let tempDir: string
const originalCwd = process.cwd()
beforeEach(() => {
tempDir = createTempProject()
process.chdir(tempDir)
})
afterEach(() => {
process.chdir(originalCwd)
rmSync(tempDir, { recursive: true, force: true })
})
it('passes props to the template via defineProps', async () => {
const result = await render(`
<script setup>
defineProps(['name'])
</script>
<template>
<div>Hello {{ name }}</div>
</template>
`, {
props: { name: 'Ava' },
})
expect(result.html).toContain('Hello Ava')
})
it('does not leak props into useConfig() or the returned config', async () => {
const result = await render(`
<script setup>
const config = useConfig()
</script>
<template>
<div>{{ config.props === undefined ? 'clean' : 'leaked' }}</div>
</template>
`, {
props: { name: 'Ava' },
})
expect(result.html).toContain('clean')
expect(result.config.props).toBeUndefined()
})
it('does not render a declared prop as a fallthrough attribute', async () => {
const result = await render(`
<script setup>
defineProps(['name'])
</script>
<template>
<div>{{ name }}</div>
</template>
`, {
props: { name: 'Ava' },
})
expect(result.html).not.toContain('name="Ava"')
})
})