11import { compile } from '../../../packages/weex-template-compiler'
2+ import { strToRegExp } from '../helpers/index'
23
34describe ( 'compile style' , ( ) => {
45 it ( 'should be compiled' , ( ) => {
56 const { render, staticRenderFns, errors } = compile ( `<div style="a: x; b: y"></div>` )
67 expect ( render ) . not . toBeUndefined ( )
78 expect ( staticRenderFns ) . not . toBeUndefined ( )
89 expect ( staticRenderFns . length ) . toEqual ( 1 )
9- expect ( staticRenderFns ) . toMatch ( / s t a t i c S t y l e \: \ {a : " x " , b : " y " \} / )
10+ expect ( staticRenderFns ) . toMatch ( strToRegExp ( ` staticStyle: {a:"x",b:"y"}` ) )
1011 expect ( errors ) . toEqual ( [ ] )
1112 } )
1213
@@ -24,7 +25,7 @@ describe('compile style', () => {
2425 expect ( render ) . not . toBeUndefined ( )
2526 expect ( staticRenderFns ) . not . toBeUndefined ( )
2627 expect ( staticRenderFns . length ) . toEqual ( 1 )
27- expect ( staticRenderFns ) . toMatch ( / s t a t i c S t y l e \: \ {a : " x " , b : " y " \} / )
28+ expect ( staticRenderFns ) . toMatch ( strToRegExp ( ` staticStyle: {a:"x",b:"y"}` ) )
2829 expect ( errors ) . toEqual ( [ ] )
2930 } )
3031
@@ -33,50 +34,50 @@ describe('compile style', () => {
3334 expect ( render ) . not . toBeUndefined ( )
3435 expect ( staticRenderFns ) . not . toBeUndefined ( )
3536 expect ( staticRenderFns . length ) . toEqual ( 1 )
36- expect ( staticRenderFns ) . toMatch ( / s t a t i c S t y l e \: \ {A b c D e f \ :" x - y " , a b c D e f \ :" x - y " \} / )
37+ expect ( staticRenderFns ) . toMatch ( strToRegExp ( ` staticStyle: {AbcDef:"x-y",abcDef:"x-y"}` ) )
3738 expect ( errors ) . toEqual ( [ ] )
3839 } )
3940
4041 it ( 'should compile dynamic style' , ( ) => {
4142 const { render, staticRenderFns, errors } = compile ( `<div style="a: x; b: {{y}}"></div>` )
4243 expect ( render ) . not . toBeUndefined ( )
4344 expect ( staticRenderFns ) . toEqual ( [ ] )
44- expect ( render ) . toMatch ( / s t y l e \: \ {a : " x " , b : _ s \( y \) \} / )
45+ expect ( render ) . toMatch ( strToRegExp ( ` style: {a:"x",b:_s(y)}` ) )
4546 expect ( errors ) . not . toBeUndefined ( )
4647 expect ( errors . length ) . toEqual ( 1 )
47- expect ( errors [ 0 ] ) . toMatch ( / b \: \{ \{ y \} \} / )
48- expect ( errors [ 0 ] ) . toMatch ( / v \ -b i n d / )
48+ expect ( errors [ 0 ] ) . toMatch ( strToRegExp ( `b: {{y}}` ) )
49+ expect ( errors [ 0 ] ) . toMatch ( strToRegExp ( `v -bind` ) )
4950 } )
5051
5152 it ( 'should compile style binding of array' , ( ) => {
5253 const { render, staticRenderFns, errors } = compile ( `<div v-bind:style="[a, b, c]"></div>` )
5354 expect ( render ) . not . toBeUndefined ( )
5455 expect ( staticRenderFns ) . toEqual ( [ ] )
55- expect ( render ) . toMatch ( / s t y l e \: \ [a , b , c \] / )
56+ expect ( render ) . toMatch ( strToRegExp ( ` style: [a, b, c]` ) )
5657 expect ( errors ) . toEqual ( [ ] )
5758 } )
5859
5960 it ( 'should compile style binding of map' , ( ) => {
6061 const { render, staticRenderFns, errors } = compile ( `<div v-bind:style="{ a: x, b: 'y' + z }"></div>` )
6162 expect ( render ) . not . toBeUndefined ( )
6263 expect ( staticRenderFns ) . toEqual ( [ ] )
63- expect ( render ) . toMatch ( / s t y l e \: \ { a \ : x , b \ : ' y ' \ + z \} / )
64+ expect ( render ) . toMatch ( strToRegExp ( ` style: { a: x, b: 'y' + z }` ) )
6465 expect ( errors ) . toEqual ( [ ] )
6566 } )
6667
6768 it ( 'should compile style binding of a variable' , ( ) => {
6869 const { render, staticRenderFns, errors } = compile ( `<div v-bind:style="x"></div>` )
6970 expect ( render ) . not . toBeUndefined ( )
7071 expect ( staticRenderFns ) . toEqual ( [ ] )
71- expect ( render ) . toMatch ( / s t y l e \: x / )
72+ expect ( render ) . toMatch ( strToRegExp ( ` style:x` ) )
7273 expect ( errors ) . toEqual ( [ ] )
7374 } )
7475
7576 it ( 'should compile style binding by shorthand' , ( ) => {
7677 const { render, staticRenderFns, errors } = compile ( `<div :style="[a, b, c]"></div>` )
7778 expect ( render ) . not . toBeUndefined ( )
7879 expect ( staticRenderFns ) . toEqual ( [ ] )
79- expect ( render ) . toMatch ( / s t y l e \: \ [a , b , c \] / )
80+ expect ( render ) . toMatch ( strToRegExp ( ` style: [a, b, c]` ) )
8081 expect ( errors ) . toEqual ( [ ] )
8182 } )
8283} )
0 commit comments