Skip to content

Commit 4d3a732

Browse files
committed
tests(directive): add test covering dynamic rows
1 parent 4ad07f8 commit 4d3a732

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

tests/directive.spec.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
/// <reference path="../typings/angularjs/angular.d.ts"/>
33
/// <reference path="../typings/jasmine/jasmine.d.ts"/>
44
describe('directive', function () {
5-
var $compile;
5+
var $compile,
6+
$rootScope;
67

78
beforeEach(module('wt.responsive'));
8-
beforeEach(inject(function (_$compile_) {
9+
beforeEach(inject(function (_$rootScope_, _$compile_) {
910
$compile = _$compile_;
11+
$rootScope = _$rootScope_;
1012
}));
11-
13+
1214
it('supports colspan', function () {
1315
var markup = [
1416
'<table wt-responsive-table>',
@@ -44,4 +46,40 @@ describe('directive', function () {
4446
expect(firstDataRow.eq(0).attr('data-title')).toBe('First title');
4547
expect(firstDataRow.eq(1).attr('data-title')).toBe('Forth title');
4648
});
49+
50+
it('supports ng-repeat applied on TR', function () {
51+
var markup = [
52+
'<table wt-responsive-table>',
53+
' <thead>',
54+
' <tr>',
55+
' <th>First title</th>',
56+
' <th>Second title</th>',
57+
' <th>Third title</th>',
58+
' <th>Forth title</th>',
59+
' </tr>',
60+
' </thead>',
61+
' <tbody>',
62+
' <tr ng-repeat="item in rows">',
63+
' <td>First column</td>',
64+
' <td>Second column</td>',
65+
' <td>Third column</td>',
66+
' <td>Forth column</td>',
67+
' </tr>',
68+
' </tbody>',
69+
'</table>'
70+
].join('');
71+
var element = angular.element(markup);
72+
var scope = $rootScope.$new();
73+
scope.rows = [0, 1];
74+
75+
var firstDataRow = element.find('tbody tr:first td');
76+
expect(firstDataRow.attr('data-title')).toBeUndefined();
77+
78+
$compile(element)(scope);
79+
80+
expect(firstDataRow.eq(0).attr('data-title')).toBe('First title');
81+
expect(firstDataRow.eq(1).attr('data-title')).toBe('Second title');
82+
expect(firstDataRow.eq(2).attr('data-title')).toBe('Third title');
83+
expect(firstDataRow.eq(3).attr('data-title')).toBe('Forth title');
84+
});
4785
});

0 commit comments

Comments
 (0)