Explorar o código

test: test case for prefixIdentifiers w/ bindings

Evan You %!s(int64=4) %!d(string=hai) anos
pai
achega
d4787e53ef
Modificáronse 1 ficheiros con 39 adicións e 0 borrados
  1. 39 0
      packages/compiler-sfc/test/prefixIdentifiers.spec.ts

+ 39 - 0
packages/compiler-sfc/test/prefixIdentifiers.spec.ts

@@ -1,6 +1,7 @@
 import { prefixIdentifiers } from '../src/prefixIdentifiers'
 import { compile } from 'web/entry-compiler'
 import { format } from 'prettier'
+import { BindingTypes } from '../src/types'
 
 it('should work', () => {
   const { render } = compile(`<div id="app">
@@ -53,3 +54,41 @@ it('should work', () => {
     "
   `)
 })
+
+it('setup bindings', () => {
+  const { render } = compile(`<div @click="count++">{{ count }}</div>`)
+
+  const result = format(
+    prefixIdentifiers(render, `render`, false, false, undefined, {
+      count: BindingTypes.SETUP_REF
+    }),
+    {
+      semi: false,
+      parser: 'babel'
+    }
+  )
+
+  expect(result).toMatch(`_setup = _vm._setupProxy`)
+  expect(result).toMatch(`_setup.count++`)
+  expect(result).toMatch(`_vm._s(_setup.count)`)
+
+  expect(result).toMatchInlineSnapshot(`
+    "function render() {
+      var _vm = this,
+        _c = _vm._self._c,
+        _setup = _vm._setupProxy
+      return _c(
+        \\"div\\",
+        {
+          on: {
+            click: function (\$event) {
+              _setup.count++
+            },
+          },
+        },
+        [_vm._v(_vm._s(_setup.count))]
+      )
+    }
+    "
+  `)
+})