Skip to content

Commit 458a568

Browse files
committed
Updated unit tests: Drop document-ready block, use #qunit-fixture instead of #main and drop extra styles now provided by QUnit.
1 parent 8351f54 commit 458a568

File tree

14 files changed

+638
-657
lines changed

14 files changed

+638
-657
lines changed

tests/unit/core/core.js

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

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-
}
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());
2131
});
2232

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

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

34-
test( "loading the core library triggers mobilinit on the document", function(){
35-
expect( 1 );
36-
37-
$(window.document).bind('mobileinit', function(event){
38-
ok(true);
39-
});
40-
41-
$.testHelper.reloadLib(libName);
42-
});
43-
44-
test( "enhancments are skipped when the browser is not grade A", function(){
45-
setGradeA(false);
46-
$.testHelper.reloadLib(libName);
40+
$.testHelper.reloadLib(libName);
41+
});
4742

48-
//NOTE easiest way to check for enhancements, not the most obvious
49-
ok(!$("html").hasClass("ui-mobile"));
50-
});
43+
test( "enhancments are skipped when the browser is not grade A", function(){
44+
setGradeA(false);
45+
$.testHelper.reloadLib(libName);
5146

52-
test( "enhancments are added when the browser is grade A", function(){
53-
setGradeA(true);
54-
$.testHelper.reloadLib(libName);
47+
//NOTE easiest way to check for enhancements, not the most obvious
48+
ok(!$("html").hasClass("ui-mobile"));
49+
});
5550

56-
ok($("html").hasClass("ui-mobile"));
57-
});
51+
test( "enhancments are added when the browser is grade A", function(){
52+
setGradeA(true);
53+
$.testHelper.reloadLib(libName);
5854

55+
ok($("html").hasClass("ui-mobile"));
56+
});
5957

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-
});
6758

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);
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+
});
7166

72-
// TODO add post reload callback
73-
$('.ui-loader').remove();
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);
7470

75-
$.mobile.pageLoading(true);
76-
ok(!$(".ui-loader").length);
77-
});
71+
// TODO add post reload callback
72+
$('.ui-loader').remove();
7873

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-
});
74+
$.mobile.pageLoading(true);
75+
ok(!$(".ui-loader").length);
76+
});
8577

86-
var metaViewportSelector = "head meta[name=viewport]",
87-
setViewPortContent = function(value){
88-
$(metaViewportSelector).remove();
89-
$.testHelper.alterExtend({metaViewportContent: value});
90-
$.testHelper.reloadLib(libName);
91-
};
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+
});
9284

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-
});
85+
var metaViewportSelector = "head meta[name=viewport]",
86+
setViewPortContent = function(value){
87+
$(metaViewportSelector).remove();
88+
$.testHelper.alterExtend({metaViewportContent: value});
89+
$.testHelper.reloadLib(libName);
90+
};
9791

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-
});
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+
});
10296

103-
var findFirstPage = function() {
104-
return $("[data-role='page']").first();
105-
};
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+
});
106101

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);
102+
var findFirstPage = function() {
103+
return $("[data-role='page']").first();
104+
};
110105

111-
same($.mobile.startPage, firstPage);
112-
same($.mobile.activePage, firstPage);
113-
});
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);
114109

115-
test( "mobile viewport class is defined on the first page's parent", function(){
116-
var firstPage = findFirstPage();
117-
$.testHelper.reloadLib(libName);
110+
same($.mobile.startPage, firstPage);
111+
same($.mobile.activePage, firstPage);
112+
});
118113

119-
ok(firstPage.parent().hasClass('ui-mobile-viewport'));
120-
});
114+
test( "mobile viewport class is defined on the first page's parent", function(){
115+
var firstPage = findFirstPage();
116+
$.testHelper.reloadLib(libName);
121117

122-
test( "mobile page container is the first page's parent", function(){
123-
var firstPage = findFirstPage();
124-
$.testHelper.reloadLib(libName);
118+
ok(firstPage.parent().hasClass('ui-mobile-viewport'));
119+
});
125120

126-
same($.mobile.pageContainer, firstPage.parent());
127-
});
121+
test( "mobile page container is the first page's parent", function(){
122+
var firstPage = findFirstPage();
123+
$.testHelper.reloadLib(libName);
128124

129-
test( "page loading is called on document ready", function(){
130-
expect( 2 );
125+
same($.mobile.pageContainer, firstPage.parent());
126+
});
131127

132-
$.testHelper.alterExtend({ pageLoading: function(){
133-
ok("called");
134-
}});
128+
test( "page loading is called on document ready", function(){
129+
expect( 2 );
135130

136-
$.testHelper.reloadLib(libName);
137-
});
131+
$.testHelper.alterExtend({ pageLoading: function(){
132+
ok("called");
133+
}});
138134

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

142-
$(window).bind("hashchange", function(ev, arg){
143-
same(arg, true);
144-
});
138+
test( "hashchange triggered on document ready with single argument: true", function(){
139+
expect( 2 );
145140

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

149-
//TODO test that silentScroll is called on window load
145+
$.testHelper.reloadLib(libName);
150146
});
151-
})(jQuery);
147+
148+
//TODO test that silentScroll is called on window load
149+
});

tests/unit/core/core_scroll.js

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

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

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

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

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

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

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

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

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

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

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();
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();
5554

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

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);
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);
6766

68-
stop();
69-
setTimeout(function(){
70-
ok($.event.special.scrollstart.enabled);
71-
start();
72-
}, scrollStartEnabledTimeout);
73-
});
74-
})(jQuery);
67+
stop();
68+
setTimeout(function(){
69+
ok($.event.special.scrollstart.enabled);
70+
start();
71+
}, scrollStartEnabledTimeout);
72+
});

0 commit comments

Comments
 (0)