feat(vModel): warn if v-model is used on file input (#295)

This commit is contained in:
Cr
2019-10-16 00:23:38 +08:00
committed by Evan You
parent 74d501829c
commit 8eba1aba08
3 changed files with 46 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
import { parse, transform, CompilerOptions } from '@vue/compiler-core'
import { transformModel } from '../../src/transforms/vModel'
import { transformElement } from '../../../compiler-core/src/transforms/transformElement'
import { DOMErrorCodes } from '../../src/errors'
function transformWithModel(template: string, options: CompilerOptions = {}) {
const ast = parse(template)
transform(ast, {
nodeTransforms: [transformElement],
directiveTransforms: {
model: transformModel
},
...options
})
return ast
}
describe('compiler: v-model transform', () => {
it('should raise error if used file input element', () => {
const onError = jest.fn()
transformWithModel(`<input type="file" v-model="test"></input>`, {
onError
})
expect(onError.mock.calls).toMatchObject([
[{ code: DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT }]
])
})
})