test(compiler-vapor): v-show directive (#130)

* test(compiler-vapor): v-show

* fix(compiler-vapor): use DOMErrorCodes in vShow test
This commit is contained in:
FireBushtree 2024-02-19 16:52:21 +08:00 committed by GitHub
parent 6c25fb612a
commit 1710bfdd21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,13 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`compiler: v-show transform > simple expression 1`] = `
"import { children as _children, vShow as _vShow, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = t0()
const n1 = _children(n0, 0)
_withDirectives(n1, [[_vShow, () => _ctx.foo]])
return n0
}"
`;

View File

@ -0,0 +1,29 @@
import { makeCompile } from './_utils'
import { transformElement, transformVShow } from '../../src'
import { DOMErrorCodes } from '@vue/compiler-dom'
const compileWithVShow = makeCompile({
nodeTransforms: [transformElement],
directiveTransforms: {
show: transformVShow,
},
})
describe('compiler: v-show transform', () => {
test('simple expression', () => {
const { code } = compileWithVShow(`<div v-show="foo"/>`)
expect(code).toMatchSnapshot()
})
test('should raise error if has no expression', () => {
const onError = vi.fn()
compileWithVShow(`<div v-show/>`, { onError })
expect(onError).toHaveBeenCalledTimes(1)
expect(onError).toHaveBeenCalledWith(
expect.objectContaining({
code: DOMErrorCodes.X_V_SHOW_NO_EXPRESSION,
}),
)
})
})