Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support v-model in weex #4178

Merged
merged 6 commits into from
Nov 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added test cases for v-model in weex
  • Loading branch information
Jinjiang committed Nov 11, 2016
commit 84817ab8cfd1979a929a9e161c563b520397b117
56 changes: 56 additions & 0 deletions test/weex/compiler/v-model.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { compile } from '../../../packages/weex-template-compiler'
import { strToRegExp } from '../helpers/index'

describe('compile v-model', () => {
it('should compile modelable native component', () => {
const { render, staticRenderFns, errors } = compile(`<div><input v-model="x" /></div>`)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp('attrs:{"value":(x)}'))
expect(render).toMatch(strToRegExp('on:{"input":function($event){x=$event.target.attr.value}}'))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})

it('should compile into render functions without runtime model directive', () => {
})

it('should compile other component with whole $event as the value', () => {
const { render, staticRenderFns, errors } = compile(`<div><foo v-model="x" /></div>`)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp('attrs:{"value":(x)}'))
expect(render).toMatch(strToRegExp('on:{"input":function($event){x=$event}}'))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})

it('should compile with lazy modifier', () => {
const { render, staticRenderFns, errors } = compile(`<div><foo v-model.lazy="x" /></div>`)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp('attrs:{"value":(x)}'))
expect(render).toMatch(strToRegExp('on:{"change":function($event){x=$event}}'))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})

it('should compile with trim modifier for modelable native component', () => {
const { render, staticRenderFns, errors } = compile(`<div><input v-model.trim="x" /><foo v-model.trim="y" /></div>`)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp('attrs:{"value":(x)}'))
expect(render).toMatch(strToRegExp('attrs:{"value":(y)}'))
expect(render).toMatch(strToRegExp('on:{"input":function($event){x=$event.target.attr.value.trim()}}'))
expect(render).toMatch(strToRegExp('on:{"input":function($event){y=$event}}'))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})

it('should compile with trim & lazy modifier', () => {
const { render, staticRenderFns, errors } = compile(`<div><input v-model.trim.lazy="x" /><input v-model.lazy.trim="y" /></div>`)
expect(render).not.toBeUndefined()
expect(render).toMatch(strToRegExp('attrs:{"value":(x)}'))
expect(render).toMatch(strToRegExp('attrs:{"value":(y)}'))
expect(render).toMatch(strToRegExp('on:{"change":function($event){x=$event.target.attr.value.trim()}}'))
expect(render).toMatch(strToRegExp('on:{"change":function($event){y=$event.target.attr.value.trim()}}'))
expect(staticRenderFns).toEqual([])
expect(errors).toEqual([])
})
})
6 changes: 6 additions & 0 deletions test/weex/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { compile } from '../../../packages/weex-template-compiler'
import { Runtime, Instance } from 'weex-vdom-tester'
import { config } from 'weex-js-runtime'

// http://stackoverflow.com/a/35478115
const matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g
export function strToRegExp(str) {
return new RegExp(str.replace(matchOperatorsRe, '\\$&'))
}

export function compileAndStringify (template) {
const { render, staticRenderFns } = compile(template)
return {
Expand Down