Skip to content

Commit

Permalink
test(compile-sfc): modify test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoErii committed Nov 15, 2023
1 parent a82a56e commit d6277b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,20 @@ return { modelValue, c, toString }
}"
`;

exports[`defineModel() > w/ Boolean And Function types, production mode 1`] = `
exports[`defineModel() > w/ Boolean types, production mode 1`] = `
"import { useModel as _useModel, defineComponent as _defineComponent } from 'vue'
export default /*#__PURE__*/_defineComponent({
props: {
\\"modelValue\\": { type: [Boolean, String] },
\\"fn\\": {},
\\"fnWithDefault\\": { type: Function, ...{ default: () => null } },
\\"optional\\": { required: false },
\\"modelValue\\": { type: [Boolean, String, Number] },
},
emits: [\\"update:modelValue\\", \\"update:fn\\", \\"update:fnWithDefault\\", \\"update:optional\\"],
emits: [\\"update:modelValue\\"],
setup(__props, { expose: __expose }) {
__expose();
const modelValue = _useModel(__props, \\"modelValue\\")
const fn = _useModel(__props, \\"fn\\")
const fnWithDefault = _useModel(__props, \\"fnWithDefault\\")
const optional = _useModel(__props, \\"optional\\")
return { modelValue, fn, fnWithDefault, optional }
return { modelValue }
}
})"
Expand Down
24 changes: 5 additions & 19 deletions packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,37 +182,23 @@ describe('defineModel()', () => {
})
})

test('w/ Boolean And Function types, production mode', () => {
test('w/ Boolean types, production mode', () => {
const { content, bindings } = compile(
`
<script setup lang="ts">
const modelValue = defineModel<boolean | string>()
const fn = defineModel<() => void>('fn')
const fnWithDefault = defineModel<() => void>('fnWithDefault', { default: () => null })
const optional = defineModel<string>('optional', { required: false })
const modelValue = defineModel<boolean | string | number>()
</script>
`,
{ defineModel: true, isProd: true }
)
assertCode(content)
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
expect(content).toMatch('"fn": {}')
expect(content).toMatch(
'"fnWithDefault": { type: Function, ...{ default: () => null } },'
)
expect(content).toMatch('"optional": { required: false }')
expect(content).toMatch(
'emits: ["update:modelValue", "update:fn", "update:fnWithDefault", "update:optional"]'
)
expect(content).toMatch('"modelValue": { type: [Boolean, String, Number] }')
expect(content).toMatch('emits: ["update:modelValue"]')
expect(content).toMatch(
`const modelValue = _useModel(__props, "modelValue")`
)
expect(content).toMatch(`const fn = _useModel(__props, "fn")`)
expect(bindings).toStrictEqual({
modelValue: BindingTypes.SETUP_REF,
fn: BindingTypes.SETUP_REF,
fnWithDefault: BindingTypes.SETUP_REF,
optional: BindingTypes.SETUP_REF
modelValue: BindingTypes.SETUP_REF
})
})
})

0 comments on commit d6277b1

Please sign in to comment.