Validating Component Exposure Mechanisms in dcloudio/uni-app
A comprehensive test suite for validating defineExpose functionality and script compilation behavior in uni-app UTS components. These tests ensure proper handling of component exposure mechanisms and script content compilation across different script tag configurations.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-app-uts/__tests__/android/sfc/compileScript/defineExpose.spec.ts
import { assertCode, compileSFCScript as compile } from '../utils'
test('defineExpose()', () => {
const { content } = compile(`
<script setup>
defineExpose({ foo: 123 })
</script>
`)
assertCode(content)
// should remove defineOptions import and call
expect(content).not.toMatch('defineExpose')
// should generate correct setup signature
// expect(content).toMatch(`setup(__props, { expose: __expose }) {`)
// should replace callee
expect(content).toMatch(/\b__expose\(\{ foo: 123 \}\)/)
})
test('<script> after <script setup> the script content not end with `\\n`', () => {
const { content } = compile(`
<script setup>
import { x } from './x'
</script>
<script>const n = 1</script>
`)
assertCode(content)
})