Skip to content

Commit e30ece1

Browse files
committed
added immediate function to prevent scoping issues in core unit tests
1 parent b671753 commit e30ece1

File tree

2 files changed

+172
-168
lines changed

2 files changed

+172
-168
lines changed

tests/unit/core/core.js

Lines changed: 112 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2,148 +2,148 @@
22
* mobile core unit tests
33
*/
44

5-
var libName = "jquery.mobile.core.js",
6-
setGradeA = function(value) { $.support.mediaquery = value; },
7-
extendFn = $.extend;
8-
9-
module(libName, {
10-
setup: function(){
11-
// NOTE reset for gradeA tests
12-
$('html').removeClass('ui-mobile');
13-
14-
// NOTE reset for pageLoading tests
15-
$('.ui-loader').remove();
16-
},
17-
teardown: function(){
18-
$.extend = extendFn;
19-
}
20-
});
21-
22-
$.testHelper.excludeFileProtocol(function(){
23-
test( "grade A browser support media queries", function(){
24-
setGradeA(false);
25-
$.testHelper.reloadLib(libName);
26-
ok(!$.mobile.gradeA());
27-
28-
setGradeA(true);
29-
$.testHelper.reloadLib(libName);
30-
ok($.mobile.gradeA());
5+
(function($){
6+
var libName = "jquery.mobile.core.js",
7+
setGradeA = function(value) { $.support.mediaquery = value; },
8+
extendFn = $.extend;
9+
10+
module(libName, {
11+
setup: function(){
12+
// NOTE reset for gradeA tests
13+
$('html').removeClass('ui-mobile');
14+
15+
// NOTE reset for pageLoading tests
16+
$('.ui-loader').remove();
17+
},
18+
teardown: function(){
19+
$.extend = extendFn;
20+
}
3121
});
3222

33-
test( "loading the core library triggers mobilinit on the document", function(){
34-
expect( 1 );
23+
$.testHelper.excludeFileProtocol(function(){
24+
test( "grade A browser support media queries", function(){
25+
setGradeA(false);
26+
$.testHelper.reloadLib(libName);
27+
ok(!$.mobile.gradeA());
3528

36-
$(window.document).bind('mobileinit', function(event){
37-
ok(true);
29+
setGradeA(true);
30+
$.testHelper.reloadLib(libName);
31+
ok($.mobile.gradeA());
3832
});
3933

40-
$.testHelper.reloadLib(libName);
41-
});
34+
test( "loading the core library triggers mobilinit on the document", function(){
35+
expect( 1 );
4236

43-
test( "enhancments are skipped when the browser is not grade A", function(){
44-
setGradeA(false);
45-
$.testHelper.reloadLib(libName);
37+
$(window.document).bind('mobileinit', function(event){
38+
ok(true);
39+
});
4640

47-
//NOTE easiest way to check for enhancements, not the most obvious
48-
ok(!$("html").hasClass("ui-mobile"));
49-
});
41+
$.testHelper.reloadLib(libName);
42+
});
5043

51-
test( "enhancments are added when the browser is grade A", function(){
52-
setGradeA(true);
53-
$.testHelper.reloadLib(libName);
44+
test( "enhancments are skipped when the browser is not grade A", function(){
45+
setGradeA(false);
46+
$.testHelper.reloadLib(libName);
5447

55-
ok($("html").hasClass("ui-mobile"));
56-
});
48+
//NOTE easiest way to check for enhancements, not the most obvious
49+
ok(!$("html").hasClass("ui-mobile"));
50+
});
5751

52+
test( "enhancments are added when the browser is grade A", function(){
53+
setGradeA(true);
54+
$.testHelper.reloadLib(libName);
5855

59-
//TODO lots of duplication
60-
test( "pageLoading doesn't add the dialog to the page when loading message is false", function(){
61-
$.testHelper.alterExtend({loadingMessage: false});
62-
$.testHelper.reloadLib(libName);
63-
$.mobile.pageLoading(false);
64-
ok(!$(".ui-loader").length);
65-
});
56+
ok($("html").hasClass("ui-mobile"));
57+
});
6658

67-
test( "pageLoading doesn't add the dialog to the page when done is passed as true", function(){
68-
$.testHelper.alterExtend({loadingMessage: true});
69-
$.testHelper.reloadLib(libName);
7059

71-
// TODO add post reload callback
72-
$('.ui-loader').remove();
60+
//TODO lots of duplication
61+
test( "pageLoading doesn't add the dialog to the page when loading message is false", function(){
62+
$.testHelper.alterExtend({loadingMessage: false});
63+
$.testHelper.reloadLib(libName);
64+
$.mobile.pageLoading(false);
65+
ok(!$(".ui-loader").length);
66+
});
7367

74-
$.mobile.pageLoading(true);
75-
ok(!$(".ui-loader").length);
76-
});
68+
test( "pageLoading doesn't add the dialog to the page when done is passed as true", function(){
69+
$.testHelper.alterExtend({loadingMessage: true});
70+
$.testHelper.reloadLib(libName);
7771

78-
test( "pageLoading adds the dialog to the page when done is true", function(){
79-
$.testHelper.alterExtend({loadingMessage: true});
80-
$.testHelper.reloadLib(libName);
81-
$.mobile.pageLoading(false);
82-
ok($(".ui-loader").length);
83-
});
72+
// TODO add post reload callback
73+
$('.ui-loader').remove();
8474

85-
var metaViewportSelector = "head meta[name=viewport]",
86-
setViewPortContent = function(value){
87-
$(metaViewportSelector).remove();
88-
$.testHelper.alterExtend({metaViewportContent: value});
89-
$.testHelper.reloadLib(libName);
90-
};
75+
$.mobile.pageLoading(true);
76+
ok(!$(".ui-loader").length);
77+
});
9178

92-
test( "meta view port element is added to head when defined on mobile", function(){
93-
setViewPortContent("width=device-width");
94-
same($(metaViewportSelector).length, 1);
95-
});
79+
test( "pageLoading adds the dialog to the page when done is true", function(){
80+
$.testHelper.alterExtend({loadingMessage: true});
81+
$.testHelper.reloadLib(libName);
82+
$.mobile.pageLoading(false);
83+
ok($(".ui-loader").length);
84+
});
9685

97-
test( "meta view port element not added to head when not defined on mobile", function(){
98-
setViewPortContent(false);
99-
same($(metaViewportSelector).length, 0);
100-
});
86+
var metaViewportSelector = "head meta[name=viewport]",
87+
setViewPortContent = function(value){
88+
$(metaViewportSelector).remove();
89+
$.testHelper.alterExtend({metaViewportContent: value});
90+
$.testHelper.reloadLib(libName);
91+
};
10192

102-
var findFirstPage = function() {
103-
return $("[data-role='page']").first();
104-
};
93+
test( "meta view port element is added to head when defined on mobile", function(){
94+
setViewPortContent("width=device-width");
95+
same($(metaViewportSelector).length, 1);
96+
});
10597

106-
test( "active page and start page should be set to the fist page in the selected set", function(){
107-
var firstPage = findFirstPage();
108-
$.testHelper.reloadLib(libName);
98+
test( "meta view port element not added to head when not defined on mobile", function(){
99+
setViewPortContent(false);
100+
same($(metaViewportSelector).length, 0);
101+
});
109102

110-
same($.mobile.startPage, firstPage);
111-
same($.mobile.activePage, firstPage);
112-
});
103+
var findFirstPage = function() {
104+
return $("[data-role='page']").first();
105+
};
113106

114-
test( "mobile viewport class is defined on the first page's parent", function(){
115-
var firstPage = findFirstPage();
116-
$.testHelper.reloadLib(libName);
107+
test( "active page and start page should be set to the fist page in the selected set", function(){
108+
var firstPage = findFirstPage();
109+
$.testHelper.reloadLib(libName);
117110

118-
ok(firstPage.parent().hasClass('ui-mobile-viewport'));
119-
});
111+
same($.mobile.startPage, firstPage);
112+
same($.mobile.activePage, firstPage);
113+
});
120114

121-
test( "mobile page container is the first page's parent", function(){
122-
var firstPage = findFirstPage();
123-
$.testHelper.reloadLib(libName);
115+
test( "mobile viewport class is defined on the first page's parent", function(){
116+
var firstPage = findFirstPage();
117+
$.testHelper.reloadLib(libName);
124118

125-
same($.mobile.pageContainer, firstPage.parent());
126-
});
119+
ok(firstPage.parent().hasClass('ui-mobile-viewport'));
120+
});
127121

128-
test( "page loading is called on document ready", function(){
129-
expect( 2 );
122+
test( "mobile page container is the first page's parent", function(){
123+
var firstPage = findFirstPage();
124+
$.testHelper.reloadLib(libName);
130125

131-
$.testHelper.alterExtend({ pageLoading: function(){
132-
ok("called");
133-
}});
126+
same($.mobile.pageContainer, firstPage.parent());
127+
});
134128

135-
$.testHelper.reloadLib(libName);
136-
});
129+
test( "page loading is called on document ready", function(){
130+
expect( 2 );
137131

138-
test( "hashchange triggered on document ready with single argument: true", function(){
139-
expect( 2 );
132+
$.testHelper.alterExtend({ pageLoading: function(){
133+
ok("called");
134+
}});
140135

141-
$(window).bind("hashchange", function(ev, arg){
142-
same(arg, true);
136+
$.testHelper.reloadLib(libName);
143137
});
144138

145-
$.testHelper.reloadLib(libName);
146-
});
139+
test( "hashchange triggered on document ready with single argument: true", function(){
140+
expect( 2 );
147141

148-
//TODO test that silentScroll is called on window load
149-
});
142+
$(window).bind("hashchange", function(ev, arg){
143+
same(arg, true);
144+
});
145+
146+
$.testHelper.reloadLib(libName);
147+
});
148+
});
149+
})(jQuery);

tests/unit/core/core_scroll.js

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,75 @@
22
* mobile core unit tests
33
*/
44

5-
var libName = "jquery.mobile.core.js",
6-
scrollTimeout = 20, // TODO expose timing as an attribute
7-
scrollStartEnabledTimeout = 150;
5+
(function($){
6+
var libName = "jquery.mobile.core.js",
7+
scrollTimeout = 20, // TODO expose timing as an attribute
8+
scrollStartEnabledTimeout = 150;
89

9-
module(libName, {
10-
setup: function(){
11-
$("<div id='scroll-testing' style='height: 1000px'></div>").appendTo("body");
12-
},
10+
module(libName, {
11+
setup: function(){
12+
$("<div id='scroll-testing' style='height: 1000px'></div>").appendTo("body");
13+
},
1314

14-
teardown: function(){
15-
$("#scroll-testing").remove();
16-
}
17-
});
15+
teardown: function(){
16+
$("#scroll-testing").remove();
17+
}
18+
});
1819

19-
var scrollUp = function( pos ){
20-
$(window).scrollTop(1000);
21-
ok($(window).scrollTop() > 0);
20+
var scrollUp = function( pos ){
21+
$(window).scrollTop(1000);
22+
ok($(window).scrollTop() > 0);
2223

23-
if(pos) {
24-
$.mobile.silentScroll(pos);
25-
} else {
26-
$.mobile.silentScroll();
27-
}
28-
};
24+
if(pos) {
25+
$.mobile.silentScroll(pos);
26+
} else {
27+
$.mobile.silentScroll();
28+
}
29+
};
2930

30-
test( "silent scroll scrolls the page to the top by default", function(){
31-
scrollUp();
31+
test( "silent scroll scrolls the page to the top by default", function(){
32+
scrollUp();
3233

33-
stop();
34-
setTimeout(function(){
35-
same($(window).scrollTop(), 0);
36-
start();
37-
}, scrollTimeout);
38-
});
34+
stop();
35+
setTimeout(function(){
36+
same($(window).scrollTop(), 0);
37+
start();
38+
}, scrollTimeout);
39+
});
3940

40-
test( "silent scroll scrolls the page to the passed y position", function(){
41-
var pos = 10;
42-
scrollUp(pos);
41+
test( "silent scroll scrolls the page to the passed y position", function(){
42+
var pos = 10;
43+
scrollUp(pos);
4344

44-
stop();
45-
setTimeout(function(){
46-
same($(window).scrollTop(), pos);
47-
start();
48-
}, scrollTimeout);
49-
});
45+
stop();
46+
setTimeout(function(){
47+
same($(window).scrollTop(), pos);
48+
start();
49+
}, scrollTimeout);
50+
});
5051

51-
// NOTE may be brittle depending on timing
52-
test( "silent scroll takes at least 20 ms to scroll to the top", function(){
53-
scrollUp();
52+
// NOTE may be brittle depending on timing
53+
test( "silent scroll takes at least 20 ms to scroll to the top", function(){
54+
scrollUp();
5455

55-
stop();
56-
setTimeout(function(){
57-
ok($(window).scrollTop() != 0);
58-
start();
59-
}, scrollTimeout - 1);
60-
});
56+
stop();
57+
setTimeout(function(){
58+
ok($(window).scrollTop() != 0);
59+
start();
60+
}, scrollTimeout - 1);
61+
});
6162

62-
test( "scrolling marks scrollstart as disabled for 150 ms", function(){
63-
$.event.special.scrollstart.enabled = true;
64-
scrollUp();
65-
ok(!$.event.special.scrollstart.enabled);
63+
test( "scrolling marks scrollstart as disabled for 150 ms", function(){
64+
$.event.special.scrollstart.enabled = true;
65+
scrollUp();
66+
ok(!$.event.special.scrollstart.enabled);
6667

67-
stop();
68-
setTimeout(function(){
69-
ok($.event.special.scrollstart.enabled);
70-
start();
71-
}, scrollStartEnabledTimeout);
72-
});
68+
stop();
69+
setTimeout(function(){
70+
ok($.event.special.scrollstart.enabled);
71+
start();
72+
}, scrollStartEnabledTimeout);
73+
});
74+
75+
//TODO test that silentScroll is called on window load
76+
})(jQuery);

0 commit comments

Comments
 (0)