Skip to content

Commit

Permalink
test: test case for prefixIdentifiers w/ bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 15, 2022
1 parent 452aa9d commit d4787e5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/compiler-sfc/test/prefixIdentifiers.spec.ts
Original file line number Diff line number Diff line change
@@ -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">
Expand Down Expand Up @@ -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))]
)
}
"
`)
})

0 comments on commit d4787e5

Please sign in to comment.