import { compile } from '../../../packages/weex-template-compiler' import { strToRegExp } from '../helpers/index' describe('compile style', () => { it('should be compiled', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).not.toBeUndefined() expect(staticRenderFns.length).toEqual(1) expect(staticRenderFns).toMatch(strToRegExp(`staticStyle:{a:"x",b:"y"}`)) expect(errors).toEqual([]) }) it('should compile empty style value', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).not.toBeUndefined() expect(staticRenderFns.length).toEqual(1) expect(staticRenderFns).toMatch(/[(^style|^staticStyle)]/) expect(errors).toEqual([]) }) it('should compile style value with trailing semicolon', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).not.toBeUndefined() expect(staticRenderFns.length).toEqual(1) expect(staticRenderFns).toMatch(strToRegExp(`staticStyle:{a:"x",b:"y"}`)) expect(errors).toEqual([]) }) it('should compile hyphanted style name & value', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).not.toBeUndefined() expect(staticRenderFns.length).toEqual(1) expect(staticRenderFns).toMatch(strToRegExp(`staticStyle:{AbcDef:"x-y",abcDef:"x-y"}`)) expect(errors).toEqual([]) }) it('should compile dynamic style', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).toEqual([]) expect(render).toMatch(strToRegExp(`style:{a:"x",b:_s(y)}`)) expect(errors).not.toBeUndefined() expect(errors.length).toEqual(1) expect(errors[0]).toMatch(strToRegExp(`b: {{y}}`)) expect(errors[0]).toMatch(strToRegExp(`v-bind`)) }) it('should compile style binding of array', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).toEqual([]) expect(render).toMatch(strToRegExp(`style:[a, b, c]`)) expect(errors).toEqual([]) }) it('should compile style binding of map', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).toEqual([]) expect(render).toMatch(strToRegExp(`style:{ a: x, b: 'y' + z }`)) expect(errors).toEqual([]) }) it('should compile style binding of a variable', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).toEqual([]) expect(render).toMatch(strToRegExp(`style:x`)) expect(errors).toEqual([]) }) it('should compile style binding by shorthand', () => { const { render, staticRenderFns, errors } = compile(`
`) expect(render).not.toBeUndefined() expect(staticRenderFns).toEqual([]) expect(render).toMatch(strToRegExp(`style:[a, b, c]`)) expect(errors).toEqual([]) }) })