@@ -48,7 +48,7 @@ describe('directive', function () {
48
48
expect ( headerRow . is ( ':offscreen' ) ) . toBe ( true ) ;
49
49
} ) ;
50
50
51
- it ( 'supports rows with no <thead>' , function ( ) {
51
+ it ( 'supports rows with no <thead>' , function ( done ) {
52
52
var markup = [
53
53
'<table wt-responsive-table>' ,
54
54
' <tr>' ,
@@ -67,22 +67,29 @@ describe('directive', function () {
67
67
] . join ( '' ) ;
68
68
var element = angular . element ( markup ) ;
69
69
document . body . appendChild ( element [ 0 ] ) ;
70
- $compile ( element ) ;
71
70
72
- var firstDataRow = element . find ( 'tr td' ) ;
73
- expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
74
- expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Second title' ) ;
75
- expect ( firstDataRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBe ( 'Third title' ) ;
76
- expect ( firstDataRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
71
+ var scope = $rootScope . $new ( ) ;
72
+ $compile ( element ) ( scope ) ;
73
+ scope . $digest ( ) ;
77
74
78
- var headerRow = element . find ( 'tr th' ) ;
79
- expect ( headerRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
80
- expect ( headerRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
81
- expect ( headerRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
82
- expect ( headerRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
75
+ setTimeout ( function ( ) {
76
+ var firstDataRow = element . find ( 'tr td' ) ;
77
+ expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
78
+ expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Second title' ) ;
79
+ expect ( firstDataRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBe ( 'Third title' ) ;
80
+ expect ( firstDataRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
81
+
82
+ var headerRow = element . find ( 'tr th' ) ;
83
+ expect ( headerRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
84
+ expect ( headerRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
85
+ expect ( headerRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
86
+ expect ( headerRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
87
+
88
+ done ( ) ;
89
+ } , 0 ) ;
83
90
} ) ;
84
91
85
- it ( 'supports <th> as first column of each <tr>' , function ( ) {
92
+ it ( 'supports <th> as first column of each <tr>' , function ( done ) {
86
93
var markup = [
87
94
'<table wt-responsive-table>' ,
88
95
' <tr>' ,
@@ -105,22 +112,29 @@ describe('directive', function () {
105
112
] . join ( '' ) ;
106
113
var element = angular . element ( markup ) ;
107
114
document . body . appendChild ( element [ 0 ] ) ;
108
- $compile ( element ) ;
109
115
110
- var firstDataRow = element . find ( 'tr td' ) ;
111
- expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
112
- expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Second title' ) ;
113
- expect ( firstDataRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBe ( 'Third title' ) ;
114
- expect ( firstDataRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
116
+ var scope = $rootScope . $new ( ) ;
117
+ $compile ( element ) ( scope ) ;
118
+ scope . $digest ( ) ;
115
119
116
- var headerRow = element . find ( 'tr th' ) ;
117
- expect ( headerRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
118
- expect ( headerRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
119
- expect ( headerRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
120
- expect ( headerRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
120
+ setTimeout ( function ( ) {
121
+ var firstDataRow = element . find ( 'tr td' ) ;
122
+ expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
123
+ expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Second title' ) ;
124
+ expect ( firstDataRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBe ( 'Third title' ) ;
125
+ expect ( firstDataRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
126
+
127
+ var headerRow = element . find ( 'tr th' ) ;
128
+ expect ( headerRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
129
+ expect ( headerRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
130
+ expect ( headerRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
131
+ expect ( headerRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
132
+
133
+ done ( ) ;
134
+ } , 0 ) ;
121
135
} ) ;
122
136
123
- it ( 'supports colspan' , function ( ) {
137
+ it ( 'supports colspan' , function ( done ) {
124
138
var markup = [
125
139
'<table wt-responsive-table>' ,
126
140
' <thead>' ,
@@ -150,13 +164,18 @@ describe('directive', function () {
150
164
var firstDataRow = element . find ( 'tbody tr:first td' ) ;
151
165
expect ( firstDataRow . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
152
166
153
- $compile ( element ) ;
167
+ var scope = $rootScope . $new ( ) ;
168
+ $compile ( element ) ( scope ) ;
169
+ scope . $digest ( ) ;
154
170
155
- expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
156
- expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
171
+ setTimeout ( function ( ) {
172
+ expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
173
+ expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
174
+ done ( ) ;
175
+ } , 0 ) ;
157
176
} ) ;
158
177
159
- it ( 'support tables with multiple static rows' , function ( ) {
178
+ it ( 'support tables with multiple static rows' , function ( done ) {
160
179
var markup = [
161
180
'<table wt-responsive-table>' ,
162
181
' <thead>' ,
@@ -187,17 +206,22 @@ describe('directive', function () {
187
206
188
207
var rows = element . find ( 'tbody tr' ) ;
189
208
190
- $compile ( element ) ;
209
+ var scope = $rootScope . $new ( ) ;
210
+ $compile ( element ) ( scope ) ;
211
+ scope . $digest ( ) ;
191
212
192
- rows . each ( function ( index , element ) {
193
- var titles = Array . prototype . map . call ( element . querySelectorAll ( 'td' ) , function ( item ) {
194
- return item . getAttribute ( 'data-title' ) ;
213
+ setTimeout ( function ( ) {
214
+ rows . each ( function ( index , element ) {
215
+ var titles = Array . prototype . map . call ( element . querySelectorAll ( 'td' ) , function ( item ) {
216
+ return item . getAttribute ( 'data-title' ) ;
217
+ } ) ;
218
+ expect ( titles ) . toEqual ( [ 'First title' , 'Second title' , 'Third title' , 'Forth title' ] ) ;
195
219
} ) ;
196
- expect ( titles ) . toEqual ( [ 'First title' , 'Second title' , 'Third title' , 'Forth title' ] ) ;
197
- } ) ;
220
+ done ( ) ;
221
+ } , 0 ) ;
198
222
} ) ;
199
223
200
- it ( 'supports ng-repeat applied on TR' , function ( ) {
224
+ it ( 'supports ng-repeat applied on TR' , function ( done ) {
201
225
var markup = [
202
226
'<table wt-responsive-table>' ,
203
227
' <thead>' ,
@@ -222,15 +246,19 @@ describe('directive', function () {
222
246
var scope = $rootScope . $new ( ) ;
223
247
scope . rows = [ 0 , 1 ] ;
224
248
225
- var firstDataRow = element . find ( 'tbody tr:first td' ) ;
226
- expect ( firstDataRow . attr ( 'data-title' ) ) . toBeUndefined ( ) ;
227
-
228
249
$compile ( element ) ( scope ) ;
250
+ scope . $digest ( ) ;
229
251
230
- expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
231
- expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Second title' ) ;
232
- expect ( firstDataRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBe ( 'Third title' ) ;
233
- expect ( firstDataRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
252
+ setTimeout ( function ( ) {
253
+ var firstDataRow = element . find ( 'tbody tr:first td' ) ;
254
+
255
+ expect ( firstDataRow . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'First title' ) ;
256
+ expect ( firstDataRow . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'Second title' ) ;
257
+ expect ( firstDataRow . eq ( 2 ) . attr ( 'data-title' ) ) . toBe ( 'Third title' ) ;
258
+ expect ( firstDataRow . eq ( 3 ) . attr ( 'data-title' ) ) . toBe ( 'Forth title' ) ;
259
+
260
+ done ( ) ;
261
+ } , 0 ) ;
234
262
} ) ;
235
263
236
264
it ( 'supports ng-repeat applied on TH' , function ( done ) {
@@ -332,7 +360,7 @@ describe('directive', function () {
332
360
} ) ;
333
361
334
362
describe ( 'responsive-dynamic' , function ( ) {
335
- it ( 'supports ng-if applied on all TDs' , function ( ) {
363
+ it ( 'supports ng-if applied on all TDs' , function ( done ) {
336
364
var markup = [
337
365
'<table wt-responsive-table>' ,
338
366
' <thead>' ,
@@ -342,8 +370,8 @@ describe('directive', function () {
342
370
' </thead>' ,
343
371
' <tbody>' ,
344
372
' <tr>' ,
345
- ' <td ng-if="!condition" responsive-dynamic >tom</td>' ,
346
- ' <td ng-if="condition" responsive-dynamic >jerry</td>' ,
373
+ ' <td ng-if="!condition">tom</td>' ,
374
+ ' <td ng-if="condition">jerry</td>' ,
347
375
' </tr>' ,
348
376
' </tbody>' ,
349
377
'</table>'
@@ -356,11 +384,14 @@ describe('directive', function () {
356
384
scope . $digest ( ) ;
357
385
358
386
var els = element . find ( 'tbody tr:first td' ) ;
359
- expect ( els . eq ( 0 ) . text ( ) ) . toBe ( 'jerry' ) ;
360
- expect ( els . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'column' ) ;
387
+ setTimeout ( function ( ) {
388
+ expect ( els . eq ( 0 ) . text ( ) ) . toBe ( 'jerry' ) ;
389
+ expect ( els . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'column' ) ;
390
+ done ( ) ;
391
+ } , 0 ) ;
361
392
} ) ;
362
393
363
- it ( 'supports ng-if applied on some TDs' , function ( ) {
394
+ it ( 'supports ng-if applied on some TDs' , function ( done ) {
364
395
var markup = [
365
396
'<table wt-responsive-table>' ,
366
397
' <thead>' ,
@@ -371,8 +402,8 @@ describe('directive', function () {
371
402
' </thead>' ,
372
403
' <tbody>' ,
373
404
' <tr>' ,
374
- ' <td ng-if="!condition" responsive-dynamic >tom</td>' ,
375
- ' <td ng-if="condition" responsive-dynamic >jerry</td>' ,
405
+ ' <td ng-if="!condition">tom</td>' ,
406
+ ' <td ng-if="condition">jerry</td>' ,
376
407
' <td>simple</td>' ,
377
408
' </tr>' ,
378
409
' </tbody>' ,
@@ -386,10 +417,13 @@ describe('directive', function () {
386
417
scope . $digest ( ) ;
387
418
388
419
var els = element . find ( 'tbody tr:first td' ) ;
389
- expect ( els . eq ( 0 ) . text ( ) ) . toBe ( 'jerry' ) ;
390
- expect ( els . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'column' ) ;
391
- expect ( els . eq ( 1 ) . text ( ) ) . toBe ( 'simple' ) ;
392
- expect ( els . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'simple' ) ;
420
+ setTimeout ( function ( ) {
421
+ expect ( els . eq ( 0 ) . text ( ) ) . toBe ( 'jerry' ) ;
422
+ expect ( els . eq ( 0 ) . attr ( 'data-title' ) ) . toBe ( 'column' ) ;
423
+ expect ( els . eq ( 1 ) . text ( ) ) . toBe ( 'simple' ) ;
424
+ expect ( els . eq ( 1 ) . attr ( 'data-title' ) ) . toBe ( 'simple' ) ;
425
+ done ( ) ;
426
+ } , 0 ) ;
393
427
} ) ;
394
428
395
429
} ) ;
0 commit comments