Przeglądaj źródła

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

* test(compiler-vapor): v-show

* fix(compiler-vapor): use DOMErrorCodes in vShow test
FireBushtree 2 lat temu
rodzic
commit
1710bfdd21

+ 13 - 0
packages/compiler-vapor/__tests__/transforms/__snapshots__/vShow.spec.ts.snap

@@ -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
+}"
+`;

+ 29 - 0
packages/compiler-vapor/__tests__/transforms/vShow.spec.ts

@@ -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,
+      }),
+    )
+  })
+})