3
3
describe ( '$interpolate' , function ( ) {
4
4
5
5
it ( 'should return the interpolation object when there are no bindings and textOnly is undefined' ,
6
- inject ( function ( $interpolate , $rootScope ) {
6
+ inject ( function ( $interpolate ) {
7
7
var interpolateFn = $interpolate ( 'some text' ) ;
8
8
9
9
expect ( interpolateFn . exp ) . toBe ( 'some text' ) ;
10
10
expect ( interpolateFn . separators ) . toEqual ( [ 'some text' ] ) ;
11
11
expect ( interpolateFn . expressions ) . toEqual ( [ ] ) ;
12
12
13
13
expect ( interpolateFn ( { } ) ) . toBe ( 'some text' ) ;
14
- expect ( interpolateFn . compute ( [ ] ) ) . toBe ( 'some text' ) ;
15
14
} ) ) ;
16
15
17
16
@@ -21,15 +20,15 @@ describe('$interpolate', function() {
21
20
} ) ) ;
22
21
23
22
it ( 'should suppress falsy objects' , inject ( function ( $interpolate ) {
24
- expect ( $interpolate ( '{{undefined}}' ) . compute ( [ undefined ] ) ) . toEqual ( '' ) ;
25
- expect ( $interpolate ( '{{null}}' ) . compute ( [ null ] ) ) . toEqual ( '' ) ;
26
- expect ( $interpolate ( '{{a.b}}' ) . compute ( [ undefined ] ) ) . toEqual ( '' ) ;
23
+ expect ( $interpolate ( '{{undefined}}' ) ( { } ) ) . toEqual ( '' ) ;
24
+ expect ( $interpolate ( '{{null}}' ) ( { } ) ) . toEqual ( '' ) ;
25
+ expect ( $interpolate ( '{{a.b}}' ) ( { } ) ) . toEqual ( '' ) ;
27
26
} ) ) ;
28
27
29
28
it ( 'should jsonify objects' , inject ( function ( $interpolate ) {
30
- expect ( $interpolate ( '{{ {} }}' ) . compute ( [ { } ] ) ) . toEqual ( '{}' ) ;
31
- expect ( $interpolate ( '{{ true }}' ) . compute ( [ true ] ) ) . toEqual ( 'true' ) ;
32
- expect ( $interpolate ( '{{ false }}' ) . compute ( [ false ] ) ) . toEqual ( 'false' ) ;
29
+ expect ( $interpolate ( '{{ {} }}' ) ( { } ) ) . toEqual ( '{}' ) ;
30
+ expect ( $interpolate ( '{{ true }}' ) ( { } ) ) . toEqual ( 'true' ) ;
31
+ expect ( $interpolate ( '{{ false }}' ) ( { } ) ) . toEqual ( 'false' ) ;
33
32
} ) ) ;
34
33
35
34
@@ -44,12 +43,11 @@ describe('$interpolate', function() {
44
43
scope . name = 'Bubu' ;
45
44
46
45
expect ( interpolateFn ( scope ) ) . toBe ( 'Hello Bubu!' ) ;
47
- expect ( interpolateFn . compute ( [ 'Bubu' ] ) ) . toBe ( 'Hello Bubu!' ) ;
48
46
} ) ) ;
49
47
50
48
51
49
it ( 'should ignore undefined model' , inject ( function ( $interpolate ) {
52
- expect ( $interpolate ( "Hello {{'World'}}{{foo}}" ) . compute ( [ 'World' ] ) ) . toBe ( 'Hello World' ) ;
50
+ expect ( $interpolate ( "Hello {{'World'}}{{foo}}" ) ( { } ) ) . toBe ( 'Hello World' ) ;
53
51
} ) ) ;
54
52
55
53
@@ -85,12 +83,12 @@ describe('$interpolate', function() {
85
83
86
84
it ( 'should interpolate trusted expressions in a regular context' , inject ( function ( $interpolate ) {
87
85
var foo = sce . trustAsCss ( "foo" ) ;
88
- expect ( $interpolate ( '{{foo}}' , true ) . compute ( [ foo ] ) ) . toEqual ( 'foo' ) ;
86
+ expect ( $interpolate ( '{{foo}}' , true ) ( { foo : foo } ) ) . toBe ( 'foo' ) ;
89
87
} ) ) ;
90
88
91
89
it ( 'should interpolate trusted expressions in a specific trustedContext' , inject ( function ( $interpolate ) {
92
90
var foo = sce . trustAsCss ( "foo" ) ;
93
- expect ( $interpolate ( '{{foo}}' , true , sce . CSS ) . compute ( [ foo ] ) ) . toEqual ( 'foo' ) ;
91
+ expect ( $interpolate ( '{{foo}}' , true , sce . CSS ) ( { foo : foo } ) ) . toBe ( 'foo' ) ;
94
92
} ) ) ;
95
93
96
94
// The concatenation of trusted values does not necessarily result in a trusted value. (For
@@ -100,7 +98,7 @@ describe('$interpolate', function() {
100
98
var foo = sce . trustAsCss ( "foo" ) ;
101
99
var bar = sce . trustAsCss ( "bar" ) ;
102
100
expect ( function ( ) {
103
- return $interpolate ( '{{foo}}{{bar}}' , true , sce . CSS ) . compute ( [ foo , bar ] ) ;
101
+ return $interpolate ( '{{foo}}{{bar}}' , true , sce . CSS ) ( { foo : foo , bar : bar } ) ;
104
102
} ) . toThrowMinErr (
105
103
"$interpolate" , "noconcat" , "Error while interpolating: {{foo}}{{bar}}\n" +
106
104
"Strict Contextual Escaping disallows interpolations that concatenate multiple " +
@@ -119,8 +117,8 @@ describe('$interpolate', function() {
119
117
it ( 'should not get confused with same markers' , inject ( function ( $interpolate ) {
120
118
expect ( $interpolate ( '---' ) . separators ) . toEqual ( [ '---' ] ) ;
121
119
expect ( $interpolate ( '---' ) . expressions ) . toEqual ( [ ] ) ;
122
- expect ( $interpolate ( '----' ) . compute ( [ ] ) ) . toEqual ( '' ) ;
123
- expect ( $interpolate ( '--1--' ) . compute ( [ 1 ] ) ) . toEqual ( '1' ) ;
120
+ expect ( $interpolate ( '----' ) ( { } ) ) . toEqual ( '' ) ;
121
+ expect ( $interpolate ( '--1--' ) ( { } ) ) . toEqual ( '1' ) ;
124
122
} ) ) ;
125
123
} ) ;
126
124
@@ -140,55 +138,55 @@ describe('$interpolate', function() {
140
138
separators = interpolateFn . separators , expressions = interpolateFn . expressions ;
141
139
expect ( separators ) . toEqual ( [ 'a' , 'C' ] ) ;
142
140
expect ( expressions ) . toEqual ( [ 'b' ] ) ;
143
- expect ( interpolateFn . compute ( [ 123 ] ) ) . toEqual ( 'a123C' ) ;
141
+ expect ( interpolateFn ( { b : 123 } ) ) . toEqual ( 'a123C' ) ;
144
142
} ) ) ;
145
143
146
144
it ( 'should Parse Ending Binding' , inject ( function ( $interpolate ) {
147
145
var interpolateFn = $interpolate ( "a{{b}}" ) ,
148
146
separators = interpolateFn . separators , expressions = interpolateFn . expressions ;
149
147
expect ( separators ) . toEqual ( [ 'a' , '' ] ) ;
150
148
expect ( expressions ) . toEqual ( [ 'b' ] ) ;
151
- expect ( interpolateFn . compute ( [ 123 ] ) ) . toEqual ( 'a123' ) ;
149
+ expect ( interpolateFn ( { b : 123 } ) ) . toEqual ( 'a123' ) ;
152
150
} ) ) ;
153
151
154
152
it ( 'should Parse Begging Binding' , inject ( function ( $interpolate ) {
155
153
var interpolateFn = $interpolate ( "{{b}}c" ) ,
156
154
separators = interpolateFn . separators , expressions = interpolateFn . expressions ;
157
155
expect ( separators ) . toEqual ( [ '' , 'c' ] ) ;
158
156
expect ( expressions ) . toEqual ( [ 'b' ] ) ;
159
- expect ( interpolateFn . compute ( [ 123 ] ) ) . toEqual ( '123c' ) ;
157
+ expect ( interpolateFn ( { b : 123 } ) ) . toEqual ( '123c' ) ;
160
158
} ) ) ;
161
159
162
160
it ( 'should Parse Loan Binding' , inject ( function ( $interpolate ) {
163
161
var interpolateFn = $interpolate ( "{{b}}" ) ,
164
162
separators = interpolateFn . separators , expressions = interpolateFn . expressions ;
165
163
expect ( separators ) . toEqual ( [ '' , '' ] ) ;
166
164
expect ( expressions ) . toEqual ( [ 'b' ] ) ;
167
- expect ( interpolateFn . compute ( [ 123 ] ) ) . toEqual ( '123' ) ;
165
+ expect ( interpolateFn ( { b : 123 } ) ) . toEqual ( '123' ) ;
168
166
} ) ) ;
169
167
170
168
it ( 'should Parse Two Bindings' , inject ( function ( $interpolate ) {
171
169
var interpolateFn = $interpolate ( "{{b}}{{c}}" ) ,
172
170
separators = interpolateFn . separators , expressions = interpolateFn . expressions ;
173
171
expect ( separators ) . toEqual ( [ '' , '' , '' ] ) ;
174
172
expect ( expressions ) . toEqual ( [ 'b' , 'c' ] ) ;
175
- expect ( interpolateFn . compute ( [ 111 , 222 ] ) ) . toEqual ( '111222' ) ;
173
+ expect ( interpolateFn ( { b : 111 , c : 222 } ) ) . toEqual ( '111222' ) ;
176
174
} ) ) ;
177
175
178
176
it ( 'should Parse Two Bindings With Text In Middle' , inject ( function ( $interpolate ) {
179
177
var interpolateFn = $interpolate ( "{{b}}x{{c}}" ) ,
180
178
separators = interpolateFn . separators , expressions = interpolateFn . expressions ;
181
179
expect ( separators ) . toEqual ( [ '' , 'x' , '' ] ) ;
182
180
expect ( expressions ) . toEqual ( [ 'b' , 'c' ] ) ;
183
- expect ( interpolateFn . compute ( [ 111 , 222 ] ) ) . toEqual ( '111x222' ) ;
181
+ expect ( interpolateFn ( { b : 111 , c : 222 } ) ) . toEqual ( '111x222' ) ;
184
182
} ) ) ;
185
183
186
184
it ( 'should Parse Multiline' , inject ( function ( $interpolate ) {
187
185
var interpolateFn = $interpolate ( '"X\nY{{A\n+B}}C\nD"' ) ,
188
186
separators = interpolateFn . separators , expressions = interpolateFn . expressions ;
189
187
expect ( separators ) . toEqual ( [ '"X\nY' , 'C\nD"' ] ) ;
190
188
expect ( expressions ) . toEqual ( [ 'A\n+B' ] ) ;
191
- expect ( interpolateFn . compute ( [ 123 ] ) ) . toEqual ( '"X\nY123C \nD"' ) ;
189
+ expect ( interpolateFn ( { 'A' : 'aa' , 'B' : 'bb' } ) ) . toEqual ( '"X\nYaabbC \nD"' ) ;
192
190
} ) ) ;
193
191
} ) ;
194
192
@@ -217,9 +215,9 @@ describe('$interpolate', function() {
217
215
} ) ) ;
218
216
219
217
it ( 'should interpolate a multi-part expression when isTrustedContext is false' , inject ( function ( $interpolate ) {
220
- expect ( $interpolate ( 'some/{{id}}' ) . compute ( [ undefined ] ) ) . toEqual ( 'some/' ) ;
221
- expect ( $interpolate ( 'some/{{id}}' ) . compute ( [ 1 ] ) ) . toEqual ( 'some/1' ) ;
222
- expect ( $interpolate ( '{{foo}}{{bar}}' ) . compute ( [ 1 , 2 ] ) ) . toEqual ( '12' ) ;
218
+ expect ( $interpolate ( 'some/{{id}}' ) ( { } ) ) . toEqual ( 'some/' ) ;
219
+ expect ( $interpolate ( 'some/{{id}}' ) ( { id : 1 } ) ) . toEqual ( 'some/1' ) ;
220
+ expect ( $interpolate ( '{{foo}}{{bar}}' ) ( { foo : 1 , bar : 2 } ) ) . toEqual ( '12' ) ;
223
221
} ) ) ;
224
222
} ) ;
225
223
@@ -251,8 +249,8 @@ describe('$interpolate', function() {
251
249
inject ( function ( $interpolate ) {
252
250
expect ( $interpolate ( '---' ) . separators ) . toEqual ( [ '---' ] ) ;
253
251
expect ( $interpolate ( '---' ) . expressions ) . toEqual ( [ ] ) ;
254
- expect ( $interpolate ( '----' ) . compute ( [ ] ) ) . toEqual ( '' ) ;
255
- expect ( $interpolate ( '--1--' ) . compute ( [ 1 ] ) ) . toEqual ( '1' ) ;
252
+ expect ( $interpolate ( '----' ) ( { } ) ) . toEqual ( '' ) ;
253
+ expect ( $interpolate ( '--1--' ) ( { } ) ) . toEqual ( '1' ) ;
256
254
} ) ;
257
255
} ) ;
258
256
} ) ;
0 commit comments