Testing Vue Template Compilation and Event Handling in uni-app H5 Platform
This test suite validates the compilation functionality in uni-app’s H5 Vite implementation, focusing on event handling and component transformations. The tests ensure proper conversion of template directives and built-in component handling for the H5 platform.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-h5-vite/__tests__/compiler.spec.ts
import { BindingTypes } from '@vue/compiler-core'
import { compileTemplate } from '@vue/compiler-sfc'
import { compilerOptions } from '../src/plugin/uni'
const filename = 'foo.vue'
function compile(source: string) {
return compileTemplate({
source,
filename,
id: filename,
compilerOptions: {
...compilerOptions,
bindingMetadata: {
canvas: BindingTypes.SETUP_REF,
},
},
})
}
describe('h5: compiler', () => {
test('tap=>click', () => {
expect(compile('<view @tap="tap"/>').code).toContain(`onClick`)
expect(compile('<map @tap="tap"/>').code).toContain(`onTap`)
})
test('builtInComponents', () => {
expect(compile('<canvas/>').code).toContain(
`_resolveComponent("v-uni-canvas")`
)
})
})