Skip to content

Commit 1710bfd

Browse files
authored
test(compiler-vapor): v-show directive (#130)
* test(compiler-vapor): v-show * fix(compiler-vapor): use DOMErrorCodes in vShow test
1 parent 6c25fb6 commit 1710bfd

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`compiler: v-show transform > simple expression 1`] = `
4+
"import { children as _children, vShow as _vShow, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
5+
const t0 = _template("<div></div>")
6+
7+
export function render(_ctx) {
8+
const n0 = t0()
9+
const n1 = _children(n0, 0)
10+
_withDirectives(n1, [[_vShow, () => _ctx.foo]])
11+
return n0
12+
}"
13+
`;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { makeCompile } from './_utils'
2+
import { transformElement, transformVShow } from '../../src'
3+
import { DOMErrorCodes } from '@vue/compiler-dom'
4+
5+
const compileWithVShow = makeCompile({
6+
nodeTransforms: [transformElement],
7+
directiveTransforms: {
8+
show: transformVShow,
9+
},
10+
})
11+
12+
describe('compiler: v-show transform', () => {
13+
test('simple expression', () => {
14+
const { code } = compileWithVShow(`<div v-show="foo"/>`)
15+
expect(code).toMatchSnapshot()
16+
})
17+
18+
test('should raise error if has no expression', () => {
19+
const onError = vi.fn()
20+
compileWithVShow(`<div v-show/>`, { onError })
21+
22+
expect(onError).toHaveBeenCalledTimes(1)
23+
expect(onError).toHaveBeenCalledWith(
24+
expect.objectContaining({
25+
code: DOMErrorCodes.X_V_SHOW_NO_EXPRESSION,
26+
}),
27+
)
28+
})
29+
})

0 commit comments

Comments
 (0)