@@ -6,19 +6,23 @@ define( [ "qunit", "jquery" ], function( QUnit, $ ) {
6
6
// TODO !! reset the prototype after every test
7
7
8
8
var mockEvent ,
9
- proto = $ . mobile . pagecontainer . prototype ,
10
- reset = $ . extend ( { } , proto ) ;
11
-
12
- proto . element = $ ( "<div>" ) ;
9
+ proto ,
10
+ reset = $ . mobile . pagecontainer . prototype ;
13
11
14
12
QUnit . module ( "Content Widget _filterNavigateEvents" , {
15
13
setup : function ( ) {
16
14
mockEvent = $ . Event ( "mock" ) ;
17
15
mockEvent . originalEvent = $ . Event ( "hashchange" ) ;
16
+ proto = reset ;
17
+ proto . element = $ ( "<div>" ) ;
18
+ reset = $ . extend ( { } , proto ) ;
19
+ } ,
20
+ teardown : function ( ) {
18
21
}
19
22
} ) ;
20
23
21
- QUnit . test ( "rejects navigate events where the original event's default is prevented" , function ( assert ) {
24
+ QUnit . test ( "rejects navigate events where the original event's default is prevented" ,
25
+ function ( assert ) {
22
26
assert . expect ( 1 ) ;
23
27
24
28
mockEvent . originalEvent . isDefaultPrevented = function ( ) {
@@ -33,7 +37,8 @@ QUnit.test( "rejects navigate events where the original event's default is preve
33
37
proto . _filterNavigateEvents ( mockEvent , { } ) ;
34
38
} ) ;
35
39
36
- QUnit . test ( "uses the hash in the state when the original event is a hashchange" , function ( assert ) {
40
+ QUnit . test ( "uses the hash in the state when the original event is a hashchange" ,
41
+ function ( assert ) {
37
42
assert . expect ( 2 ) ;
38
43
39
44
proto . _handleNavigate = function ( url , state ) {
@@ -44,7 +49,8 @@ QUnit.test( "uses the hash in the state when the original event is a hashchange"
44
49
proto . _filterNavigateEvents ( mockEvent , { state : { hash : "foo" } } ) ;
45
50
} ) ;
46
51
47
- QUnit . test ( "uses the url in the state when the original event is NOT a hashchange" , function ( assert ) {
52
+ QUnit . test ( "uses the url in the state when the original event is NOT a hashchange" ,
53
+ function ( assert ) {
48
54
assert . expect ( 2 ) ;
49
55
50
56
mockEvent . originalEvent = $ . Event ( "other" ) ;
@@ -57,7 +63,8 @@ QUnit.test( "uses the url in the state when the original event is NOT a hashchan
57
63
proto . _filterNavigateEvents ( mockEvent , { state : { url : "bar" } } ) ;
58
64
} ) ;
59
65
60
- QUnit . test ( "uses the current hash when no url or hash is present" , function ( assert ) {
66
+ QUnit . test ( "uses the current hash when no url or hash is present" ,
67
+ function ( assert ) {
61
68
assert . expect ( 1 ) ;
62
69
63
70
proto . _handleNavigate = function ( url , state ) {
@@ -87,7 +94,9 @@ QUnit.test( "uses the current url when no hash is present", function( assert ) {
87
94
88
95
QUnit . module ( "Content Widget _handleDialog" , {
89
96
setup : function ( ) {
90
- proto = $ . mobile . pagecontainer . prototype ;
97
+ proto = reset ;
98
+ proto . element = $ ( "<div>" ) ;
99
+ reset = $ . extend ( { } , proto ) ;
91
100
}
92
101
} ) ;
93
102
@@ -102,7 +111,8 @@ QUnit.test( "continues backward when the active content isn't a dialog", functio
102
111
assert . ok ( true , "back called" ) ;
103
112
} ;
104
113
105
- assert . ok ( ! proto . _handleDialog ( { } , { direction : "back" } ) , "returns false to prevent action" ) ;
114
+ assert . ok ( ! proto . _handleDialog ( { } , { direction : "back" } ) ,
115
+ "returns false to prevent action" ) ;
106
116
} ) ;
107
117
108
118
QUnit . test ( "continues forward when the active content isn't a dialog" , function ( assert ) {
@@ -116,7 +126,8 @@ QUnit.test( "continues forward when the active content isn't a dialog", function
116
126
assert . ok ( true , "forward called" ) ;
117
127
} ;
118
128
119
- assert . ok ( ! proto . _handleDialog ( { } , { direction : "forward" } ) , "returns false to prevent action" ) ;
129
+ assert . ok ( ! proto . _handleDialog ( { } , { direction : "forward" } ) ,
130
+ "returns false to prevent action" ) ;
120
131
} ) ;
121
132
122
133
QUnit . test ( "extends changePageOptions when current content is a dialog" , function ( assert ) {
@@ -172,7 +183,10 @@ var base = "http://example.com/";
172
183
173
184
QUnit . module ( "Content Widget _handleDestination" , {
174
185
setup : function ( ) {
175
- proto = $ . mobile . pagecontainer . prototype ;
186
+ proto = reset ;
187
+ proto . element = $ ( "<div>" ) ;
188
+ reset = $ . extend ( { } , proto ) ;
189
+
176
190
proto . _getHistory = function ( ) {
177
191
return {
178
192
initialDst : "foo" ,
@@ -186,23 +200,32 @@ QUnit.module( "Content Widget _handleDestination", {
186
200
}
187
201
} ) ;
188
202
189
- QUnit . test ( "skips manipulation and returns the initial content if two is falsey" , function ( assert ) {
203
+ QUnit . test ( "skips manipulation and returns the initial content if two is falsey" ,
204
+ function ( assert ) {
190
205
proto . _getInitialContent = function ( ) {
191
206
return "initial content" ;
192
207
} ;
193
208
194
209
assert . equal ( "initial content" , proto . _handleDestination ( "" ) , "avoids manip" ) ;
195
210
} ) ;
196
211
197
- QUnit . test ( "returns an absolute url when the argument is just a hash" , function ( assert ) {
212
+ QUnit . test ( "returns an absolute url when the argument is just a hash" ,
213
+ function ( assert ) {
198
214
assert . equal ( base + "#foo" , proto . _handleDestination ( "#foo" ) ) ;
199
215
} ) ;
200
216
201
- QUnit . test ( "returns the hashless value when the argument is a path" , function ( assert ) {
217
+ QUnit . test ( "returns the hashless value when the argument is a path" ,
218
+ function ( assert ) {
202
219
assert . equal ( "foo/bar" , proto . _handleDestination ( "#foo/bar" ) ) ;
203
220
} ) ;
204
221
205
- QUnit . module ( "Content Widget _recordScroll" ) ;
222
+ QUnit . module ( "Content Widget _recordScroll" , {
223
+ setup : function ( ) {
224
+ proto = reset ;
225
+ proto . element = $ ( "<div>" ) ;
226
+ reset = $ . extend ( { } , proto ) ;
227
+ }
228
+ } ) ;
206
229
207
230
QUnit . test ( "does not record scroll position when disabled" , function ( assert ) {
208
231
assert . expect ( 0 ) ;
@@ -215,7 +238,8 @@ QUnit.test( "does not record scroll position when disabled", function( assert )
215
238
proto . _recordScroll ( ) ;
216
239
} ) ;
217
240
218
- QUnit . test ( "prefers last scroll when it's larger than the minimum scroll" , function ( assert ) {
241
+ QUnit . test ( "prefers last scroll when it's larger than the minimum scroll" ,
242
+ function ( assert ) {
219
243
assert . expect ( 1 ) ;
220
244
221
245
var active = { } ;
@@ -238,7 +262,8 @@ QUnit.test( "prefers last scroll when it's larger than the minimum scroll", func
238
262
assert . equal ( active . lastScroll , 100 , "should be equal to _getScroll value" ) ;
239
263
} ) ;
240
264
241
- QUnit . test ( "prefers default scroll when current scroll < default scroll" , function ( assert ) {
265
+ QUnit . test ( "prefers default scroll when current scroll < default scroll" ,
266
+ function ( assert ) {
242
267
assert . expect ( 1 ) ;
243
268
244
269
var active = { } ;
@@ -265,15 +290,18 @@ QUnit.test( "prefers default scroll when current scroll < default scroll", funct
265
290
266
291
QUnit . module ( "Content Widget _find" , {
267
292
setup : function ( ) {
293
+ proto = reset ;
294
+ proto . element = $ ( "<div>" ) ;
295
+ reset = $ . extend ( { } , proto ) ;
296
+
268
297
proto . _getNs = function ( ) {
269
298
return "foo-" ;
270
299
} ;
271
-
272
- proto . element = $ ( "<div>" ) ;
273
300
}
274
301
} ) ;
275
302
276
- QUnit . test ( "returns the page container child matching the dataUrl first" , function ( assert ) {
303
+ QUnit . test ( "returns the page container child matching the dataUrl first" ,
304
+ function ( assert ) {
277
305
this . element = $ ( "<div><div data-foo-url='bar'></div></div>" ) ;
278
306
279
307
assert . equal (
@@ -283,7 +311,8 @@ QUnit.test( "returns the page container child matching the dataUrl first", funct
283
311
) ;
284
312
} ) ;
285
313
286
- QUnit . test ( "returns the child with the dataUrl id and corrects the data-url attr" , function ( assert ) {
314
+ QUnit . test ( "returns the child with the dataUrl id and corrects the data-url attr" ,
315
+ function ( assert ) {
287
316
var result ;
288
317
289
318
proto . element = $ ( "<div><div id='bar'></div></div>" ) ;
@@ -313,6 +342,9 @@ QUnit.test( "returns the first page when nothing matches", function( assert ) {
313
342
QUnit . module ( "Content Widget _parse" , {
314
343
setup : function ( ) {
315
344
$ . mobile . ns = "foo-" ;
345
+ proto = reset ;
346
+ proto . element = $ ( "<div>" ) ;
347
+ reset = $ . extend ( { } , proto ) ;
316
348
}
317
349
} ) ;
318
350
@@ -338,7 +370,8 @@ QUnit.test( "returns first page with data role dialog", function( assert ) {
338
370
assert . equal ( page . attr ( "data-foo-role" ) , "dialog" ) ;
339
371
} ) ;
340
372
341
- QUnit . test ( "returns the body of the html wrapped in a page when no page exists" , function ( assert ) {
373
+ QUnit . test ( "returns the body of the html wrapped in a page when no page exists" ,
374
+ function ( assert ) {
342
375
var html , page ;
343
376
344
377
html = "<body>foo</body>" ;
@@ -352,10 +385,14 @@ QUnit.test( "returns the body of the html wrapped in a page when no page exists"
352
385
QUnit . module ( "Content Widget _setLoadedTitle" , {
353
386
setup : function ( ) {
354
387
$ . mobile . ns = "foo-" ;
388
+ proto = reset ;
389
+ proto . element = $ ( "<div>" ) ;
390
+ reset = $ . extend ( { } , proto ) ;
355
391
}
356
392
} ) ;
357
393
358
- QUnit . test ( "does nothing where the title is already defined for the page" , function ( assert ) {
394
+ QUnit . test ( "does nothing where the title is already defined for the page" ,
395
+ function ( assert ) {
359
396
var html , page , pageHtml ;
360
397
361
398
pageHtml = "<div data-foo-role='page' data-foo-title='bar'></div>" ;
@@ -391,9 +428,16 @@ QUnit.test( "prevents injection", function( assert ) {
391
428
assert . equal ( page . jqmData ( "title" ) , undefined ) ;
392
429
} ) ;
393
430
394
- QUnit . module ( "Content Widget _triggerWithDeprecated" ) ;
431
+ QUnit . module ( "Content Widget _triggerWithDeprecated" , {
432
+ setup : function ( ) {
433
+ proto = reset ;
434
+ proto . element = $ ( "<div>" ) ;
435
+ reset = $ . extend ( { } , proto ) ;
436
+ }
437
+ } ) ;
395
438
396
- QUnit . test ( "triggers both content* and page* events and includes data" , function ( assert ) {
439
+ QUnit . test ( "triggers both content* and page* events and includes data" ,
440
+ function ( assert ) {
397
441
assert . expect ( 4 ) ;
398
442
399
443
proto . element . bind ( "pagefoo" , function ( event , data ) {
@@ -409,7 +453,13 @@ QUnit.test( "triggers both content* and page* events and includes data", functio
409
453
proto . _triggerWithDeprecated ( "foo" , { bar : "baz" } ) ;
410
454
} ) ;
411
455
412
- QUnit . module ( "Content Widget _include" ) ;
456
+ QUnit . module ( "Content Widget _include" , {
457
+ setup : function ( ) {
458
+ proto = reset ;
459
+ proto . element = $ ( "<div>" ) ;
460
+ reset = $ . extend ( { } , proto ) ;
461
+ }
462
+ } ) ;
413
463
414
464
QUnit . test ( "include appends to the element" , function ( assert ) {
415
465
var page = $ ( "<div>" ) ;
0 commit comments