@@ -17,6 +17,8 @@ describe('Binders', () => {
17
17
debounceGetValue : false
18
18
} ;
19
19
20
+ const mappingFn = value => `mapping_${ value } ` ;
21
+
20
22
let obj ;
21
23
let node ;
22
24
@@ -33,14 +35,30 @@ describe('Binders', () => {
33
35
expect ( node . someProp ) . toEqual ( 'bar' ) ;
34
36
} ) ;
35
37
38
+ it ( 'should bind prop and use mapping function' , ( ) => {
39
+ node . someProp = 'foo' ;
40
+ bindNode ( obj , 'x' , node , prop ( 'someProp' , mappingFn ) , noDebounceFlag ) ;
41
+ expect ( obj . x ) . toEqual ( 'foo' ) ;
42
+ obj . x = 'bar' ;
43
+ expect ( node . someProp ) . toEqual ( 'mapping_bar' ) ;
44
+ } ) ;
45
+
36
46
it ( 'should bind attr' , ( ) => {
37
47
node . setAttribute ( 'some-attribute' , 'foo' ) ;
38
- bindNode ( obj , 'x' , node , attr ( 'someProp ' ) , noDebounceFlag ) ;
39
- expect ( node . getAttribute ( 'some-attribute' ) ) . toEqual ( 'foo' ) ;
40
- node . setAttribute ( 'some-attribute' , 'bar' ) ;
48
+ bindNode ( obj , 'x' , node , attr ( 'some-attribute ' ) , noDebounceFlag ) ;
49
+ expect ( obj . x ) . toEqual ( 'foo' ) ;
50
+ obj . x = 'bar' ;
41
51
expect ( node . getAttribute ( 'some-attribute' ) ) . toEqual ( 'bar' ) ;
42
52
} ) ;
43
53
54
+ it ( 'should bind attr and use mapping function' , ( ) => {
55
+ node . setAttribute ( 'some-attribute' , 'foo' ) ;
56
+ bindNode ( obj , 'x' , node , attr ( 'some-attribute' , mappingFn ) , noDebounceFlag ) ;
57
+ expect ( obj . x ) . toEqual ( 'foo' ) ;
58
+ obj . x = 'bar' ;
59
+ expect ( node . getAttribute ( 'some-attribute' ) ) . toEqual ( 'mapping_bar' ) ;
60
+ } ) ;
61
+
44
62
it ( 'should bind html' , ( ) => {
45
63
node . innerHTML = '<i>foo</i>' ;
46
64
bindNode ( obj , 'x' , node , html ( ) , noDebounceFlag ) ;
@@ -49,6 +67,14 @@ describe('Binders', () => {
49
67
expect ( node . innerHTML ) . toEqual ( '<b>bar</b>' ) ;
50
68
} ) ;
51
69
70
+ it ( 'should bind html and use mapping function' , ( ) => {
71
+ node . innerHTML = '<i>foo</i>' ;
72
+ bindNode ( obj , 'x' , node , html ( mappingFn ) , noDebounceFlag ) ;
73
+ expect ( obj . x ) . toEqual ( '<i>foo</i>' ) ;
74
+ obj . x = '<b>bar</b>' ;
75
+ expect ( node . innerHTML ) . toEqual ( 'mapping_<b>bar</b>' ) ;
76
+ } ) ;
77
+
52
78
it ( 'should bind text' , ( ) => {
53
79
node . textContent = '<i>foo</i>' ;
54
80
bindNode ( obj , 'x' , node , text ( ) , noDebounceFlag ) ;
@@ -57,6 +83,14 @@ describe('Binders', () => {
57
83
expect ( node . textContent ) . toEqual ( '<b>bar</b>' ) ;
58
84
} ) ;
59
85
86
+ it ( 'should bind text and use mapping function' , ( ) => {
87
+ node . textContent = '<i>foo</i>' ;
88
+ bindNode ( obj , 'x' , node , text ( mappingFn ) , noDebounceFlag ) ;
89
+ expect ( obj . x ) . toEqual ( '<i>foo</i>' ) ;
90
+ obj . x = '<b>bar</b>' ;
91
+ expect ( node . textContent ) . toEqual ( 'mapping_<b>bar</b>' ) ;
92
+ } ) ;
93
+
60
94
it ( 'should bind style' , ( ) => {
61
95
node . style . textAlign = 'center' ;
62
96
bindNode ( obj , 'x' , node , style ( 'textAlign' ) , noDebounceFlag ) ;
@@ -65,6 +99,32 @@ describe('Binders', () => {
65
99
expect ( node . style . textAlign ) . toEqual ( 'right' ) ;
66
100
} ) ;
67
101
102
+ it ( 'should bind style and use mapping function' , ( ) => {
103
+ node . style . background = 'red' ;
104
+ bindNode ( obj , 'x' , node , style ( 'background' , url => `url("${ url } ")` ) , noDebounceFlag ) ;
105
+ expect ( obj . x ) . toEqual ( 'red' ) ;
106
+ obj . x = 'cats.jpg' ;
107
+ expect ( node . style . background ) . toEqual ( 'url("cats.jpg")' ) ;
108
+ } ) ;
109
+
110
+ it ( 'should bind dataset' , ( ) => {
111
+ // @IE 9
112
+ node . setAttribute ( 'data-foo' , 'bar' ) ;
113
+ bindNode ( obj , 'x' , node , dataset ( 'foo' ) , noDebounceFlag ) ;
114
+ expect ( obj . x ) . toEqual ( 'bar' ) ;
115
+ obj . x = 'baz' ;
116
+ expect ( node . getAttribute ( 'data-foo' ) ) . toEqual ( 'baz' ) ;
117
+ } ) ;
118
+
119
+ it ( 'should bind dataset and use mapping function' , ( ) => {
120
+ // @IE 9
121
+ node . setAttribute ( 'data-foo' , 'bar' ) ;
122
+ bindNode ( obj , 'x' , node , dataset ( 'foo' , mappingFn ) , noDebounceFlag ) ;
123
+ expect ( obj . x ) . toEqual ( 'bar' ) ;
124
+ obj . x = 'baz' ;
125
+ expect ( node . getAttribute ( 'data-foo' ) ) . toEqual ( 'mapping_baz' ) ;
126
+ } ) ;
127
+
68
128
it ( 'should bind display' , ( ) => {
69
129
node . style . display = 'none' ;
70
130
bindNode ( obj , 'x' , node , display ( true ) , noDebounceFlag ) ;
@@ -93,13 +153,4 @@ describe('Binders', () => {
93
153
obj . x = true ;
94
154
expect ( node . className ) . toEqual ( '' ) ;
95
155
} ) ;
96
-
97
- it ( 'should bind dataset' , ( ) => {
98
- // @IE 9
99
- node . setAttribute ( 'data-foo' , 'bar' ) ;
100
- bindNode ( obj , 'x' , node , dataset ( 'foo' ) , noDebounceFlag ) ;
101
- expect ( obj . x ) . toEqual ( 'bar' ) ;
102
- obj . x = 'baz' ;
103
- expect ( node . getAttribute ( 'data-foo' ) ) . toEqual ( 'baz' ) ;
104
- } ) ;
105
156
} ) ;
0 commit comments