vOn.mp.spec.ts 828 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import { ElementNode } from '@vue/compiler-core'
import { compile } from '../src'
import { X_V_ON_DYNAMIC_EVENT } from '../src/errors'
import { CompilerOptions } from '../src/options'

function parseWithVOn(template: string, options: CompilerOptions = {}) {
  const { ast } = compile(template, options)
  return {
    root: ast,
    node: ast.children[0] as ElementNode,
  }
}

describe('compiler(mp): transform v-on', () => {
  test('should error if dynamic event', () => {
    const onError = jest.fn()
    parseWithVOn(`<div v-on:[event]="onClick" />`, { onError })
    expect(onError.mock.calls[0][0]).toMatchObject({
      code: X_V_ON_DYNAMIC_EVENT,
      loc: {
        start: {
          line: 1,
          column: 6,
        },
        end: {
          line: 1,
          column: 28,
        },
      },
    })
  })
})