mirror of https://github.com/vuejs/core.git
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:
parent
6c25fb612a
commit
1710bfdd21
|
@ -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
|
||||||
|
}"
|
||||||
|
`;
|
|
@ -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,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue