@@ -10,33 +10,33 @@ describe('ngId', function() {
10
10
it ( 'should add new and remove old ids dynamically' , inject ( function ( $rootScope , $compile ) {
11
11
element = $compile ( '<div id="existing" ng-id="dynId"></div>' ) ( $rootScope ) ;
12
12
13
- expect ( element . attr ( 'id' ) === 'existing' ) . toBe ( true ) ;
13
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBeTruthy ( ) ;
14
14
15
15
$rootScope . dynId = 'A' ;
16
16
$rootScope . $digest ( ) ;
17
- expect ( element . attr ( 'id' ) === 'existing' ) . toBe ( false ) ;
18
- expect ( element . attr ( 'id' ) === 'A' ) . toBe ( true ) ;
17
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBeFalsy ( ) ;
18
+ expect ( element . attr ( 'id' ) === 'A' ) . toBeTruthy ( ) ;
19
19
20
20
$rootScope . dynId = 'B' ;
21
21
$rootScope . $digest ( ) ;
22
- expect ( element . attr ( 'id' ) === 'existing' ) . toBe ( false ) ;
23
- expect ( element . attr ( 'id' ) === 'A' ) . toBe ( false ) ;
24
- expect ( element . attr ( 'id' ) === 'B' ) . toBe ( true ) ;
22
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBeFalsy ( ) ;
23
+ expect ( element . attr ( 'id' ) === 'A' ) . toBeFalsy ( ) ;
24
+ expect ( element . attr ( 'id' ) === 'B' ) . toBeTruthy ( ) ;
25
25
26
26
delete $rootScope . dynId ;
27
27
$rootScope . $digest ( ) ;
28
- expect ( element . attr ( 'id' ) === 'existing' ) . toBe ( true ) ;
29
- expect ( element . attr ( 'id' ) === 'A' ) . toBe ( false ) ;
30
- expect ( element . attr ( 'id' ) === 'B' ) . toBe ( false ) ;
28
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBeTruthy ( ) ;
29
+ expect ( element . attr ( 'id' ) === 'A' ) . toBeFalsy ( ) ;
30
+ expect ( element . attr ( 'id' ) === 'B' ) . toBeFalsy ( ) ;
31
31
} ) ) ;
32
32
33
33
34
34
it ( 'should support not support ids via an array' , inject ( function ( $rootScope , $compile ) {
35
35
element = $compile ( '<div id="existing" ng-id="[\'A\', \'B\']"></div>' ) ( $rootScope ) ;
36
36
$rootScope . $digest ( ) ;
37
- expect ( element . attr ( 'id' ) === 'existing' ) . toBe ( true ) ;
38
- expect ( element . attr ( 'id' ) === 'A' ) . toBe ( false ) ;
39
- expect ( element . attr ( 'id' ) === 'B' ) . toBe ( false ) ;
37
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBeTruthy ( ) ;
38
+ expect ( element . attr ( 'id' ) === 'A' ) . toBeFalsy ( ) ;
39
+ expect ( element . attr ( 'id' ) === 'B' ) . toBeFalsy ( ) ;
40
40
} ) ) ;
41
41
42
42
@@ -48,8 +48,8 @@ describe('ngId', function() {
48
48
'</div>' ) ( $rootScope ) ;
49
49
$rootScope . conditionA = true ;
50
50
$rootScope . $digest ( ) ;
51
- expect ( element . attr ( 'id' ) === 'existing' ) . toBeFalsy ;
52
- expect ( element . attr ( 'id' ) === 'A' ) . toBeTruthy ;
51
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBeFalsy ( ) ;
52
+ expect ( element . attr ( 'id' ) === 'A' ) . toBeTruthy ( ) ;
53
53
expect ( element . attr ( 'id' ) === 'B' ) . toBeFalsy ( ) ;
54
54
expect ( element . attr ( 'id' ) === 'AnotB' ) . toBeFalsy ( ) ;
55
55
@@ -84,85 +84,55 @@ describe('ngId', function() {
84
84
} ) ) ;
85
85
86
86
87
- // it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) {
88
- // element = $compile('<div class="existing" ng-class="\'A B\'"></div>')($rootScope);
89
- // $rootScope.$digest();
90
- // expect(element.hasClass('existing')).toBeTruthy();
91
- // expect(element.hasClass('A')).toBeTruthy();
92
- // expect(element.hasClass('B')).toBeTruthy();
93
- // }));
94
-
95
-
96
- // it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope, $compile) {
97
- // element = $compile('<div class="existing" ng-class="dynClass"></div>')($rootScope);
98
- // $rootScope.dynClass = 'A';
99
- // $rootScope.$digest();
100
- // expect(element.hasClass('existing')).toBe(true);
101
-
102
- // // add extra class, change model and eval
103
- // element.addClass('newClass');
104
- // $rootScope.dynClass = 'B';
105
- // $rootScope.$digest();
106
-
107
- // expect(element.hasClass('existing')).toBe(true);
108
- // expect(element.hasClass('B')).toBe(true);
109
- // expect(element.hasClass('newClass')).toBe(true);
110
- // }));
111
-
112
-
113
- // it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope, $compile) {
114
- // element = $compile('<div ng-class="dynClass"></div>')($rootScope);
115
- // $rootScope.dynClass = 'A';
116
- // $rootScope.$digest();
117
- // expect(element.hasClass('A')).toBe(true);
118
-
119
- // // add extra class, change model and eval
120
- // element.addClass('newClass');
121
- // $rootScope.dynClass = 'B';
122
- // $rootScope.$digest();
123
-
124
- // expect(element.hasClass('B')).toBe(true);
125
- // expect(element.hasClass('newClass')).toBe(true);
126
- // }));
87
+ it ( 'should return only the first word in a space delimited string' , inject ( function ( $rootScope , $compile ) {
88
+ element = $compile ( '<div id="existing" ng-id="\'A B\'"></div>' ) ( $rootScope ) ;
89
+ $rootScope . $digest ( ) ;
90
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBeFalsy ( ) ;
91
+ expect ( element . attr ( 'id' ) === 'A' ) . toBeTruthy ( ) ;
92
+ expect ( element . attr ( 'id' ) === 'B' ) . toBeFalsy ( ) ;
93
+ } ) ) ;
127
94
128
95
129
- // it('should preserve other classes with similar name"', inject(function($rootScope, $compile) {
130
- // element = $compile('<div class="ui-panel ui-selected" ng-class="dynCls"></div>')($rootScope);
131
- // $rootScope.dynCls = 'panel';
132
- // $rootScope.$digest();
133
- // $rootScope.dynCls = 'foo';
134
- // $rootScope.$digest();
135
- // expect(element[0].className).toBe('ui-panel ui-selected ng-scope foo');
136
- // }));
96
+ it ( 'should replace id added post compilation with pre-existing ng-id value' , inject ( function ( $rootScope , $compile ) {
97
+ element = $compile ( '<div id="existing" ng-id="dynId"></div>' ) ( $rootScope ) ;
98
+ $rootScope . dynId = 'A' ;
99
+ $rootScope . $digest ( ) ;
100
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBe ( false ) ;
137
101
102
+ // add extra class, change model and eval
103
+ element . attr ( 'id' , 'newId' ) ;
104
+ $rootScope . dynId = 'B' ;
105
+ $rootScope . $digest ( ) ;
138
106
139
- // it('should not add duplicate classes', inject(function($rootScope, $compile) {
140
- // element = $compile('<div class="panel bar" ng-class="dynCls"></div>')($rootScope);
141
- // $rootScope.dynCls = 'panel';
142
- // $rootScope.$digest();
143
- // expect(element[0].className).toBe('panel bar ng-scope');
144
- // }));
107
+ expect ( element . attr ( 'id' ) === 'existing' ) . toBe ( false ) ;
108
+ expect ( element . attr ( 'id' ) === 'B' ) . toBe ( true ) ;
109
+ expect ( element . attr ( 'id' ) === 'newid' ) . toBe ( false ) ;
110
+ } ) ) ;
145
111
146
112
147
- // it('should remove classes even if it was specified via class attribute', inject(function($rootScope, $compile) {
148
- // element = $compile('<div class="panel bar" ng-class="dynCls"></div>')($rootScope);
149
- // $rootScope.dynCls = 'panel';
150
- // $rootScope.$digest();
151
- // $rootScope.dynCls = 'window';
152
- // $rootScope.$digest();
153
- // expect(element[0].className).toBe('bar ng-scope window');
154
- // }));
113
+ it ( 'should replace id added post compilation without pre-existing ids"' , inject ( function ( $rootScope , $compile ) {
114
+ element = $compile ( '<div ng-id="dynId"></div>' ) ( $rootScope ) ;
115
+ $rootScope . dynId = 'A' ;
116
+ $rootScope . $digest ( ) ;
117
+ expect ( element . attr ( 'id' ) === 'A' ) . toBe ( true ) ;
155
118
119
+ // add extra class, change model and eval
120
+ element . attr ( 'id' , 'newId' ) ;
121
+ $rootScope . dynId = 'B' ;
122
+ $rootScope . $digest ( ) ;
156
123
157
- // it('should remove classes even if they were added by another code', inject(function($rootScope, $compile) {
158
- // element = $compile('<div ng-class="dynCls"></div>')($rootScope);
159
- // $rootScope.dynCls = 'foo';
160
- // $rootScope.$digest();
161
- // element.addClass('foo');
162
- // $rootScope.dynCls = '';
163
- // $rootScope.$digest();
164
- // }));
124
+ expect ( element . attr ( 'id' ) === 'B' ) . toBe ( true ) ;
125
+ expect ( element . attr ( 'id' ) === 'newid' ) . toBe ( false ) ;
126
+ } ) ) ;
165
127
128
+ it ( 'should remove ids even if it was specified via id attribute' , inject ( function ( $rootScope , $compile ) {
129
+ element = $compile ( '<div id="existing" ng-class="dynId"></div>' ) ( $rootScope ) ;
130
+ $rootScope . dynId = 'A' ;
131
+ $rootScope . $digest ( ) ;
132
+ $rootScope . dynId = 'B' ;
133
+ $rootScope . $digest ( ) ;
134
+ expect ( element . attr ( 'id' ) === 'B' ) . toBe ( true ) ;
135
+ } ) ) ;
166
136
167
137
// it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) {
168
138
// element = $compile('<div ng-class="dynCls"></div>')($rootScope);
@@ -176,10 +146,10 @@ describe('ngId', function() {
176
146
// $rootScope.$digest();
177
147
// var e1 = jqLite(element[0].childNodes[1]);
178
148
// var e2 = jqLite(element[0].childNodes[3]);
179
- // expect(e1.hasClass('existing')).toBeTruthy ();
180
- // expect(e1.hasClass('odd')).toBeTruthy ();
181
- // expect(e2.hasClass('existing')).toBeTruthy ();
182
- // expect(e2.hasClass('even')).toBeTruthy ();
149
+ // expect(e1.hasClass('existing')).attr('id') === y ();
150
+ // expect(e1.hasClass('odd')).attr('id') === y ();
151
+ // expect(e2.hasClass('existing')).attr('id') === y ();
152
+ // expect(e2.hasClass('even')).attr('id') === y ();
183
153
// }));
184
154
185
155
@@ -192,11 +162,11 @@ describe('ngId', function() {
192
162
// var e1 = jqLite(element[0].childNodes[1]);
193
163
// var e2 = jqLite(element[0].childNodes[3]);
194
164
195
- // expect(e1.hasClass('plainClass')).toBeTruthy ();
196
- // expect(e1.hasClass('odd')).toBeTruthy ();
165
+ // expect(e1.hasClass('plainClass')).attr('id') === y ();
166
+ // expect(e1.hasClass('odd')).attr('id') === y ();
197
167
// expect(e1.hasClass('even')).toBeFalsy();
198
- // expect(e2.hasClass('plainClass')).toBeTruthy ();
199
- // expect(e2.hasClass('even')).toBeTruthy ();
168
+ // expect(e2.hasClass('plainClass')).attr('id') === y ();
169
+ // expect(e2.hasClass('even')).attr('id') === y ();
200
170
// expect(e2.hasClass('odd')).toBeFalsy();
201
171
// }));
202
172
@@ -208,10 +178,10 @@ describe('ngId', function() {
208
178
// $rootScope.$digest();
209
179
// var e1 = jqLite(element[0].childNodes[1]);
210
180
// var e2 = jqLite(element[0].childNodes[5]);
211
- // expect(e1.hasClass('same')).toBeTruthy ();
212
- // expect(e1.hasClass('odd')).toBeTruthy ();
213
- // expect(e2.hasClass('same')).toBeTruthy ();
214
- // expect(e2.hasClass('odd')).toBeTruthy ();
181
+ // expect(e1.hasClass('same')).attr('id') === y ();
182
+ // expect(e1.hasClass('odd')).attr('id') === y ();
183
+ // expect(e2.hasClass('same')).attr('id') === y ();
184
+ // expect(e2.hasClass('odd')).attr('id') === y ();
215
185
// }));
216
186
217
187
// it('should allow both ngClass and ngClassOdd/Even with multiple classes', inject(function($rootScope, $compile) {
@@ -223,17 +193,17 @@ describe('ngId', function() {
223
193
// var e1 = jqLite(element[0].childNodes[1]);
224
194
// var e2 = jqLite(element[0].childNodes[3]);
225
195
226
- // expect(e1.hasClass('A')).toBeTruthy ();
227
- // expect(e1.hasClass('B')).toBeTruthy ();
228
- // expect(e1.hasClass('C')).toBeTruthy ();
229
- // expect(e1.hasClass('D')).toBeTruthy ();
196
+ // expect(e1.hasClass('A')).attr('id') === y ();
197
+ // expect(e1.hasClass('B')).attr('id') === y ();
198
+ // expect(e1.hasClass('C')).attr('id') === y ();
199
+ // expect(e1.hasClass('D')).attr('id') === y ();
230
200
// expect(e1.hasClass('E')).toBeFalsy();
231
201
// expect(e1.hasClass('F')).toBeFalsy();
232
202
233
- // expect(e2.hasClass('A')).toBeTruthy ();
234
- // expect(e2.hasClass('B')).toBeTruthy ();
235
- // expect(e2.hasClass('E')).toBeTruthy ();
236
- // expect(e2.hasClass('F')).toBeTruthy ();
203
+ // expect(e2.hasClass('A')).attr('id') === y ();
204
+ // expect(e2.hasClass('B')).attr('id') === y ();
205
+ // expect(e2.hasClass('E')).attr('id') === y ();
206
+ // expect(e2.hasClass('F')).attr('id') === y ();
237
207
// expect(e2.hasClass('C')).toBeFalsy();
238
208
// expect(e2.hasClass('D')).toBeFalsy();
239
209
// }));
@@ -297,10 +267,10 @@ describe('ngId', function() {
297
267
// var e1 = jqLite(element[0].childNodes[1]);
298
268
// var e2 = jqLite(element[0].childNodes[3]);
299
269
300
- // expect(e1.hasClass('odd')).toBeTruthy ();
270
+ // expect(e1.hasClass('odd')).attr('id') === y ();
301
271
// expect(e1.hasClass('even')).toBeFalsy();
302
272
303
- // expect(e2.hasClass('even')).toBeTruthy ();
273
+ // expect(e2.hasClass('even')).attr('id') === y ();
304
274
// expect(e2.hasClass('odd')).toBeFalsy();
305
275
// }));
306
276
@@ -319,10 +289,10 @@ describe('ngId', function() {
319
289
// var e1 = jqLite(element[0].childNodes[1]);
320
290
// var e2 = jqLite(element[0].childNodes[3]);
321
291
322
- // expect(e1.hasClass('odd')).toBeTruthy ();
292
+ // expect(e1.hasClass('odd')).attr('id') === y ();
323
293
// expect(e1.hasClass('even')).toBeFalsy();
324
294
325
- // expect(e2.hasClass('even')).toBeTruthy ();
295
+ // expect(e2.hasClass('even')).attr('id') === y ();
326
296
// expect(e2.hasClass('odd')).toBeFalsy();
327
297
// }));
328
298
} ) ;
0 commit comments