Skip to content

Commit 60ea6ac

Browse files
committed
wip: Add a test case for adding the components option
1 parent 0969238 commit 60ea6ac

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,22 @@ return { foo, bar, baz, y, z }
606606
}"
607607
`;
608608

609+
exports[`SFC compile <script setup> component imports 1`] = `
610+
"import SubComponent from \\"subcomponent.vue\\"
611+
import OtherComponent from \\"OtherComponent.vue\\"
612+
613+
export default {
614+
components: { SubComponent, OtherComponent },
615+
setup(__props, { expose }) {
616+
expose();
617+
618+
619+
return { SubComponent, OtherComponent }
620+
}
621+
622+
}"
623+
`;
624+
609625
exports[`SFC compile <script setup> defineEmits() 1`] = `
610626
"export default {
611627
emits: ['foo', 'bar'],

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

+12
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ defineExpose({ foo: 123 })
168168
expect(content).toMatch(/\bexpose\(\{ foo: 123 \}\)/)
169169
})
170170

171+
test('component imports', () => {
172+
const { content } = compile(`
173+
<script setup>
174+
import SubComponent from "subcomponent.vue"
175+
import OtherComponent from "OtherComponent.vue"
176+
</script>
177+
`)
178+
assertCode(content)
179+
// imported components should be declared in the components option
180+
expect(content).toMatch('components: { SubComponent, OtherComponent }')
181+
});
182+
171183
test('<script> after <script setup> the script content not end with `\\n`', () => {
172184
const { content } = compile(`
173185
<script setup>

0 commit comments

Comments
 (0)