Skip to content

Commit

Permalink
test: disallow
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Apr 5, 2023
1 parent 6c9ac2d commit 4607c27
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,48 @@ const myEmit = defineEmits(['foo', 'bar'])
'[@vue/compiler-sfc] defineOptions() cannot be used to declare props. Use defineProps() instead.'
)
})

it('should emit an error with declaring props/emits/slots/expose', () => {
expect(() =>
compile(`
<script setup>
defineOptions({ props: ['foo'] })
</script>
`)
).toThrowError(
'[@vue/compiler-sfc] defineOptions() cannot be used to declare props. Use defineProps() instead'
)

expect(() =>
compile(`
<script setup>
defineOptions({ emits: ['update'] })
</script>
`)
).toThrowError(
'[@vue/compiler-sfc] defineOptions() cannot be used to declare emits. Use defineEmits() instead'
)

expect(() =>
compile(`
<script setup>
defineOptions({ expose: ['foo'] })
</script>
`)
).toThrowError(
'[@vue/compiler-sfc] defineOptions() cannot be used to declare expose. Use defineExpose() instead'
)

expect(() =>
compile(`
<script setup lang="ts">
defineOptions({ slots: Object })
</script>
`)
).toThrowError(
'[@vue/compiler-sfc] defineOptions() cannot be used to declare slots. Use defineSlots() instead'
)
})
})

test('defineExpose()', () => {
Expand Down

0 comments on commit 4607c27

Please sign in to comment.