Skip to content

Commit e7742da

Browse files
committed
test: improve
1 parent e8a821e commit e7742da

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
@@ -1585,38 +1585,43 @@ const emit = defineEmits(['a', 'b'])
15851585
assertCode(content)
15861586
})
15871587

1588-
test('defineSlots', () => {
1589-
const { content } = compile(`
1590-
<script setup lang="ts">
1591-
const slots = defineSlots<{
1592-
default: { msg: string }
1593-
}>()
1594-
</script>
1595-
`)
1596-
assertCode(content)
1597-
expect(content).toMatch(`const slots = _useSlots()`)
1598-
})
1588+
describe('defineSlots()', () => {
1589+
test('basic usage', () => {
1590+
const { content } = compile(`
1591+
<script setup lang="ts">
1592+
const slots = defineSlots<{
1593+
default: { msg: string }
1594+
}>()
1595+
</script>
1596+
`)
1597+
assertCode(content)
1598+
expect(content).toMatch(`const slots = _useSlots()`)
1599+
expect(content).not.toMatch('defineSlots')
1600+
})
15991601

1600-
test('defineSlots w/o return value', () => {
1601-
const { content } = compile(`
1602-
<script setup lang="ts">
1603-
defineSlots<{
1604-
default: { msg: string }
1605-
}>()
1606-
</script>
1607-
`)
1608-
assertCode(content)
1609-
expect(content).not.toMatch(`_useSlots`)
1610-
})
1602+
test('w/o return value', () => {
1603+
const { content } = compile(`
1604+
<script setup lang="ts">
1605+
defineSlots<{
1606+
default: { msg: string }
1607+
}>()
1608+
</script>
1609+
`)
1610+
assertCode(content)
1611+
expect(content).not.toMatch('defineSlots')
1612+
expect(content).not.toMatch(`_useSlots`)
1613+
})
16111614

1612-
test('defineSlots w/o generic params', () => {
1613-
const { content } = compile(`
1614-
<script setup>
1615-
const slots = defineSlots()
1616-
</script>
1617-
`)
1618-
assertCode(content)
1619-
expect(content).toMatch(`const slots = _useSlots()`)
1615+
test('w/o generic params', () => {
1616+
const { content } = compile(`
1617+
<script setup>
1618+
const slots = defineSlots()
1619+
</script>
1620+
`)
1621+
assertCode(content)
1622+
expect(content).toMatch(`const slots = _useSlots()`)
1623+
expect(content).not.toMatch('defineSlots')
1624+
})
16201625
})
16211626

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

0 commit comments

Comments
 (0)