Skip to content

Commit bde1cd2

Browse files
committed
a new test on template error
1 parent c164394 commit bde1cd2

File tree

2 files changed

+98
-90
lines changed

2 files changed

+98
-90
lines changed

test/BasicSetupSpec.js

Lines changed: 98 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,111 @@
11
/*global describe, beforeEach, module, inject, it, spyOn, expect, $, runTest */
2-
describe('uiScroll', function () {
3-
'use strict';
2+
describe('uiScroll', function() {
3+
'use strict';
44

5-
beforeEach(module('ui.scroll'));
6-
beforeEach(module('ui.scroll.test.datasources'));
5+
beforeEach(module('ui.scroll'));
6+
beforeEach(module('ui.scroll.test.datasources'));
77

8-
describe('basic setup', function () {
9-
var scrollSettings = {datasource: 'myEmptyDatasource'};
8+
describe('basic setup', function() {
109

11-
it('should bind to window scroll and resize events and unbind them after the scope is destroyed', function () {
12-
spyOn($.fn, 'bind').and.callThrough();
13-
spyOn($.fn, 'unbind').and.callThrough();
14-
runTest(scrollSettings,
15-
function (viewport) {
16-
expect($.fn.bind.calls.all().length).toBe(3);
17-
expect($.fn.bind.calls.all()[0].args[0]).toBe('mousewheel');
18-
expect($.fn.bind.calls.all()[0].object[0]).toBe(viewport[0]);
19-
expect($.fn.bind.calls.all()[1].args[0]).toBe('resize');
20-
expect($.fn.bind.calls.all()[1].object[0]).toBe(viewport[0]);
21-
expect($.fn.bind.calls.all()[2].args[0]).toBe('scroll');
22-
expect($.fn.bind.calls.all()[2].object[0]).toBe(viewport[0]);
23-
}, {
24-
cleanupTest: function (viewport, scope, $timeout) {
25-
$timeout(function () {
26-
expect($.fn.unbind.calls.all().length).toBe(3);
27-
expect($.fn.unbind.calls.all()[0].args[0]).toBe('resize');
28-
expect($.fn.unbind.calls.all()[0].object[0]).toBe(viewport[0]);
29-
expect($.fn.unbind.calls.all()[1].args[0]).toBe('scroll');
30-
expect($.fn.unbind.calls.all()[1].object[0]).toBe(viewport[0]);
31-
expect($.fn.unbind.calls.all()[2].args[0]).toBe('mousewheel');
32-
expect($.fn.unbind.calls.all()[2].object[0]).toBe(viewport[0]);
33-
});
34-
}
35-
}
36-
);
10+
it('should throw an error if the template\'s wrong', function() {
11+
runTest({ datasource: 'myEmptyDatasource', extra: 'ng-if="false"' }, null, {
12+
catch: function(error) {
13+
expect(error.message).toBe('ui-scroll directive requires an Element node for templating the view');
14+
}
15+
}
16+
);
17+
});
18+
19+
var scrollSettings = { datasource: 'myEmptyDatasource' };
20+
21+
it('should bind to window scroll and resize events and unbind them after the scope is destroyed', function() {
22+
spyOn($.fn, 'bind').and.callThrough();
23+
spyOn($.fn, 'unbind').and.callThrough();
24+
runTest(scrollSettings,
25+
function(viewport) {
26+
expect($.fn.bind.calls.all().length).toBe(3);
27+
expect($.fn.bind.calls.all()[0].args[0]).toBe('mousewheel');
28+
expect($.fn.bind.calls.all()[0].object[0]).toBe(viewport[0]);
29+
expect($.fn.bind.calls.all()[1].args[0]).toBe('resize');
30+
expect($.fn.bind.calls.all()[1].object[0]).toBe(viewport[0]);
31+
expect($.fn.bind.calls.all()[2].args[0]).toBe('scroll');
32+
expect($.fn.bind.calls.all()[2].object[0]).toBe(viewport[0]);
33+
}, {
34+
cleanupTest: function(viewport, scope, $timeout) {
35+
$timeout(function() {
36+
expect($.fn.unbind.calls.all().length).toBe(3);
37+
expect($.fn.unbind.calls.all()[0].args[0]).toBe('resize');
38+
expect($.fn.unbind.calls.all()[0].object[0]).toBe(viewport[0]);
39+
expect($.fn.unbind.calls.all()[1].args[0]).toBe('scroll');
40+
expect($.fn.unbind.calls.all()[1].object[0]).toBe(viewport[0]);
41+
expect($.fn.unbind.calls.all()[2].args[0]).toBe('mousewheel');
42+
expect($.fn.unbind.calls.all()[2].object[0]).toBe(viewport[0]);
3743
});
44+
}
45+
}
46+
);
47+
});
3848

39-
it('should create 2 divs of 0 height', function () {
40-
runTest(scrollSettings,
41-
function (viewport) {
42-
expect(viewport.children().length).toBe(2);
49+
it('should create 2 divs of 0 height', function() {
50+
runTest(scrollSettings,
51+
function(viewport) {
52+
expect(viewport.children().length).toBe(2);
4353

44-
var topPadding = viewport.children()[0];
45-
expect(topPadding.tagName.toLowerCase()).toBe('div');
46-
expect(angular.element(topPadding).css('height')).toBe('0px');
54+
var topPadding = viewport.children()[0];
55+
expect(topPadding.tagName.toLowerCase()).toBe('div');
56+
expect(angular.element(topPadding).css('height')).toBe('0px');
4757

48-
var bottomPadding = viewport.children()[1];
49-
expect(bottomPadding.tagName.toLowerCase()).toBe('div');
50-
expect(angular.element(bottomPadding).css('height')).toBe('0px');
51-
}
52-
);
53-
});
58+
var bottomPadding = viewport.children()[1];
59+
expect(bottomPadding.tagName.toLowerCase()).toBe('div');
60+
expect(angular.element(bottomPadding).css('height')).toBe('0px');
61+
}
62+
);
63+
});
5464

55-
it('should call get on the datasource 2 times ', function () {
56-
var spy;
57-
inject(function (myEmptyDatasource) {
58-
spy = spyOn(myEmptyDatasource, 'get').and.callThrough();
59-
});
60-
runTest(scrollSettings,
61-
function () {
62-
expect(spy.calls.all().length).toBe(2);
63-
expect(spy.calls.all()[0].args.length).toBe(3);
64-
expect(spy.calls.all()[0].args[0]).toBe(1);
65-
expect(spy.calls.all()[0].args[1]).toBe(10);
66-
expect(spy.calls.all()[1].args.length).toBe(3);
67-
expect(spy.calls.all()[1].args[0]).toBe(-9);
68-
expect(spy.calls.all()[1].args[1]).toBe(10);
69-
}
70-
);
71-
});
72-
});
65+
it('should call get on the datasource 2 times ', function() {
66+
var spy;
67+
inject(function(myEmptyDatasource) {
68+
spy = spyOn(myEmptyDatasource, 'get').and.callThrough();
69+
});
70+
runTest(scrollSettings,
71+
function() {
72+
expect(spy.calls.all().length).toBe(2);
73+
expect(spy.calls.all()[0].args.length).toBe(3);
74+
expect(spy.calls.all()[0].args[0]).toBe(1);
75+
expect(spy.calls.all()[0].args[1]).toBe(10);
76+
expect(spy.calls.all()[1].args.length).toBe(3);
77+
expect(spy.calls.all()[1].args[0]).toBe(-9);
78+
expect(spy.calls.all()[1].args[1]).toBe(10);
79+
}
80+
);
81+
});
82+
});
7383

74-
describe('basic setup (new datasource get signature)', function () {
75-
var scrollSettings = {datasource: 'myNewEmptyDatasource'};
84+
describe('basic setup (new datasource get signature)', function() {
85+
var scrollSettings = { datasource: 'myNewEmptyDatasource' };
7686

77-
it('should call get on the datasource 2 times ', function () {
78-
var spy;
79-
inject(function (myNewEmptyDatasource) {
80-
spy = spyOn(myNewEmptyDatasource, 'actualGet').and.callThrough();
81-
});
82-
runTest(scrollSettings,
83-
function () {
84-
expect(spy.calls.all().length).toBe(2);
85-
expect(spy.calls.all()[0].args.length).toBe(2);
86-
expect(spy.calls.all()[0].args[0].index).toBe(1);
87-
expect(spy.calls.all()[0].args[0].count).toBe(10);
88-
expect('append' in spy.calls.all()[0].args[0]).toBe(true);
89-
expect(spy.calls.all()[0].args[0].append).toBeUndefined();
90-
expect('prepend' in spy.calls.all()[0].args[0]).toBe(false);
91-
expect(spy.calls.all()[1].args.length).toBe(2);
92-
expect(spy.calls.all()[1].args[0].index).toBe(-9);
93-
expect(spy.calls.all()[1].args[0].count).toBe(10);
94-
expect('append' in spy.calls.all()[1].args[0]).toBe(false);
95-
expect('prepend' in spy.calls.all()[1].args[0]).toBe(true);
96-
expect(spy.calls.all()[1].args[0].prepend).toBeUndefined();
97-
}
98-
);
99-
});
87+
it('should call get on the datasource 2 times ', function() {
88+
var spy;
89+
inject(function(myNewEmptyDatasource) {
90+
spy = spyOn(myNewEmptyDatasource, 'actualGet').and.callThrough();
91+
});
92+
runTest(scrollSettings,
93+
function() {
94+
expect(spy.calls.all().length).toBe(2);
95+
expect(spy.calls.all()[0].args.length).toBe(2);
96+
expect(spy.calls.all()[0].args[0].index).toBe(1);
97+
expect(spy.calls.all()[0].args[0].count).toBe(10);
98+
expect('append' in spy.calls.all()[0].args[0]).toBe(true);
99+
expect(spy.calls.all()[0].args[0].append).toBeUndefined();
100+
expect('prepend' in spy.calls.all()[0].args[0]).toBe(false);
101+
expect(spy.calls.all()[1].args.length).toBe(2);
102+
expect(spy.calls.all()[1].args[0].index).toBe(-9);
103+
expect(spy.calls.all()[1].args[0].count).toBe(10);
104+
expect('append' in spy.calls.all()[1].args[0]).toBe(false);
105+
expect('prepend' in spy.calls.all()[1].args[0]).toBe(true);
106+
expect(spy.calls.all()[1].args[0].prepend).toBeUndefined();
107+
}
108+
);
100109
});
110+
});
101111
});

test/UserIndiciesSpec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ describe('uiScroll main/max indicies', function() {
6262
});
6363

6464
it('should work with maxIndex pre-set on datasource', function() {
65-
var setMinIndex;
6665
inject(function(myInfiniteDatasource) {
6766
myInfiniteDatasource.maxIndex = userMaxIndex;
6867
});
@@ -77,7 +76,6 @@ describe('uiScroll main/max indicies', function() {
7776
});
7877

7978
it('should work with minIndex pre-set on datasource', function() {
80-
var setMinIndex;
8179
inject(function(myInfiniteDatasource) {
8280
myInfiniteDatasource.minIndex = userMinIndex;
8381
});

0 commit comments

Comments
 (0)