Skip to content

Commit 7f6f9c9

Browse files
committed
test: improve
1 parent 527170c commit 7f6f9c9

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+9-9
Original file line numberDiff line numberDiff line change
@@ -1785,45 +1785,45 @@ return { props, emit }
17851785
})"
17861786
`;
17871787

1788-
exports[`SFC compile <script setup> > with TypeScript > defineSlots 1`] = `
1788+
exports[`SFC compile <script setup> > with TypeScript > defineSlots() > basic usage 1`] = `
17891789
"import { useSlots as _useSlots, defineComponent as _defineComponent } from 'vue'
17901790

17911791
export default /*#__PURE__*/_defineComponent({
17921792
setup(__props, { expose: __expose }) {
17931793
__expose();
17941794

1795-
const slots = _useSlots()
1796-
1795+
const slots = _useSlots()
1796+
17971797
return { slots }
17981798
}
17991799

18001800
})"
18011801
`;
18021802

1803-
exports[`SFC compile <script setup> > with TypeScript > defineSlots w/o generic params 1`] = `
1803+
exports[`SFC compile <script setup> > with TypeScript > defineSlots() > w/o generic params 1`] = `
18041804
"import { useSlots as _useSlots } from 'vue'
18051805

18061806
export default {
18071807
setup(__props, { expose: __expose }) {
18081808
__expose();
18091809

1810-
const slots = _useSlots()
1811-
1810+
const slots = _useSlots()
1811+
18121812
return { slots }
18131813
}
18141814

18151815
}"
18161816
`;
18171817

1818-
exports[`SFC compile <script setup> > with TypeScript > defineSlots w/o return value 1`] = `
1818+
exports[`SFC compile <script setup> > with TypeScript > defineSlots() > w/o return value 1`] = `
18191819
"import { defineComponent as _defineComponent } from 'vue'
18201820

18211821
export default /*#__PURE__*/_defineComponent({
18221822
setup(__props, { expose: __expose }) {
18231823
__expose();
18241824

1825-
1826-
1825+
1826+
18271827
return { }
18281828
}
18291829

packages/compiler-sfc/__tests__/compileScript.spec.ts

+35-30
Original file line numberDiff line numberDiff line change
@@ -1540,38 +1540,43 @@ const emit = defineEmits(['a', 'b'])
15401540
assertCode(content)
15411541
})
15421542

1543-
test('defineSlots', () => {
1544-
const { content } = compile(`
1545-
<script setup lang="ts">
1546-
const slots = defineSlots<{
1547-
default: { msg: string }
1548-
}>()
1549-
</script>
1550-
`)
1551-
assertCode(content)
1552-
expect(content).toMatch(`const slots = _useSlots()`)
1553-
})
1543+
describe('defineSlots()', () => {
1544+
test('basic usage', () => {
1545+
const { content } = compile(`
1546+
<script setup lang="ts">
1547+
const slots = defineSlots<{
1548+
default: { msg: string }
1549+
}>()
1550+
</script>
1551+
`)
1552+
assertCode(content)
1553+
expect(content).toMatch(`const slots = _useSlots()`)
1554+
expect(content).not.toMatch('defineSlots')
1555+
})
15541556

1555-
test('defineSlots w/o return value', () => {
1556-
const { content } = compile(`
1557-
<script setup lang="ts">
1558-
defineSlots<{
1559-
default: { msg: string }
1560-
}>()
1561-
</script>
1562-
`)
1563-
assertCode(content)
1564-
expect(content).not.toMatch(`_useSlots`)
1565-
})
1557+
test('w/o return value', () => {
1558+
const { content } = compile(`
1559+
<script setup lang="ts">
1560+
defineSlots<{
1561+
default: { msg: string }
1562+
}>()
1563+
</script>
1564+
`)
1565+
assertCode(content)
1566+
expect(content).not.toMatch('defineSlots')
1567+
expect(content).not.toMatch(`_useSlots`)
1568+
})
15661569

1567-
test('defineSlots w/o generic params', () => {
1568-
const { content } = compile(`
1569-
<script setup>
1570-
const slots = defineSlots()
1571-
</script>
1572-
`)
1573-
assertCode(content)
1574-
expect(content).toMatch(`const slots = _useSlots()`)
1570+
test('w/o generic params', () => {
1571+
const { content } = compile(`
1572+
<script setup>
1573+
const slots = defineSlots()
1574+
</script>
1575+
`)
1576+
assertCode(content)
1577+
expect(content).toMatch(`const slots = _useSlots()`)
1578+
expect(content).not.toMatch('defineSlots')
1579+
})
15751580
})
15761581

15771582
test('runtime Enum', () => {

0 commit comments

Comments
 (0)