Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Apr 20, 2023
1 parent fd27683 commit 81e3639
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,44 @@ return { props }
})"
`;

exports[`defineProps > w/ Partial<interface> 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
interface Props { x: number }
export default /*#__PURE__*/_defineComponent({
props: {
x: { type: Number, required: false }
},
setup(__props: any, { expose: __expose }) {
__expose();
return { }
}
})"
`;
exports[`defineProps > w/ Required<interface> 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
interface Props { x?: number }
export default /*#__PURE__*/_defineComponent({
props: {
x: { type: Number, required: true }
},
setup(__props: any, { expose: __expose }) {
__expose();
return { }
}
})"
`;
exports[`defineProps > w/ TS assertion 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
Expand Down
28 changes: 28 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,34 @@ const props = defineProps({ foo: String })
})
})

test('w/ Required<interface>', () => {
const { content, bindings } = compile(`
<script setup lang="ts">
interface Props { x?: number }
defineProps<Required<Props>>()
</script>
`)
assertCode(content)
expect(content).toMatch(`x: { type: Number, required: true }`)
expect(bindings).toStrictEqual({
x: BindingTypes.PROPS
})
})

test('w/ Partial<interface>', () => {
const { content, bindings } = compile(`
<script setup lang="ts">
interface Props { x: number }
defineProps<Partial<Props>>()
</script>
`)
assertCode(content)
expect(content).toMatch(`x: { type: Number, required: false }`)
expect(bindings).toStrictEqual({
x: BindingTypes.PROPS
})
})

test('w/ extends interface', () => {
const { content, bindings } = compile(`
<script lang="ts">
Expand Down

0 comments on commit 81e3639

Please sign in to comment.