Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit f806e3d

Browse files
committed
Content: Add proper teardown for all tests
Closes #8236
1 parent ce83a9d commit f806e3d

File tree

2 files changed

+79
-28
lines changed

2 files changed

+79
-28
lines changed

build/tasks/options/jscs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ return {
9494
"tests/unit/popup/popup_core.js",
9595
"tests/unit/loader/loader_core.js",
9696
"tests/unit/loader/backcompat_core.js",
97-
"tests/unit/panel/panel_core.js"
97+
"tests/unit/panel/panel_core.js",
98+
"tests/unit/content/content_core.js"
9899
]
99100
},
100101
tests: {

tests/unit/content/content_core.js

+77-27
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@ define( [ "qunit", "jquery" ], function( QUnit, $ ) {
66
// TODO !! reset the prototype after every test
77

88
var mockEvent,
9-
proto = $.mobile.pagecontainer.prototype,
10-
reset = $.extend( {}, proto );
11-
12-
proto.element = $( "<div>" );
9+
proto,
10+
reset = $.mobile.pagecontainer.prototype;
1311

1412
QUnit.module( "Content Widget _filterNavigateEvents", {
1513
setup: function() {
1614
mockEvent = $.Event( "mock" );
1715
mockEvent.originalEvent = $.Event( "hashchange" );
16+
proto = reset;
17+
proto.element = $( "<div>" );
18+
reset = $.extend( {}, proto );
19+
},
20+
teardown: function() {
1821
}
1922
} );
2023

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 ) {
2226
assert.expect( 1 );
2327

2428
mockEvent.originalEvent.isDefaultPrevented = function() {
@@ -33,7 +37,8 @@ QUnit.test( "rejects navigate events where the original event's default is preve
3337
proto._filterNavigateEvents( mockEvent, {} );
3438
} );
3539

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 ) {
3742
assert.expect( 2 );
3843

3944
proto._handleNavigate = function( url, state ) {
@@ -44,7 +49,8 @@ QUnit.test( "uses the hash in the state when the original event is a hashchange"
4449
proto._filterNavigateEvents( mockEvent, { state: { hash: "foo" } } );
4550
} );
4651

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 ) {
4854
assert.expect( 2 );
4955

5056
mockEvent.originalEvent = $.Event( "other" );
@@ -57,7 +63,8 @@ QUnit.test( "uses the url in the state when the original event is NOT a hashchan
5763
proto._filterNavigateEvents( mockEvent, { state: { url: "bar" } } );
5864
} );
5965

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 ) {
6168
assert.expect( 1 );
6269

6370
proto._handleNavigate = function( url, state ) {
@@ -87,7 +94,9 @@ QUnit.test( "uses the current url when no hash is present", function( assert ) {
8794

8895
QUnit.module( "Content Widget _handleDialog", {
8996
setup: function() {
90-
proto = $.mobile.pagecontainer.prototype;
97+
proto = reset;
98+
proto.element = $( "<div>" );
99+
reset = $.extend( {}, proto );
91100
}
92101
} );
93102

@@ -102,7 +111,8 @@ QUnit.test( "continues backward when the active content isn't a dialog", functio
102111
assert.ok( true, "back called" );
103112
};
104113

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" );
106116
} );
107117

108118
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
116126
assert.ok( true, "forward called" );
117127
};
118128

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" );
120131
} );
121132

122133
QUnit.test( "extends changePageOptions when current content is a dialog", function( assert ) {
@@ -172,7 +183,10 @@ var base = "http://example.com/";
172183

173184
QUnit.module( "Content Widget _handleDestination", {
174185
setup: function() {
175-
proto = $.mobile.pagecontainer.prototype;
186+
proto = reset;
187+
proto.element = $( "<div>" );
188+
reset = $.extend( {}, proto );
189+
176190
proto._getHistory = function() {
177191
return {
178192
initialDst: "foo",
@@ -186,23 +200,32 @@ QUnit.module( "Content Widget _handleDestination", {
186200
}
187201
} );
188202

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 ) {
190205
proto._getInitialContent = function() {
191206
return "initial content";
192207
};
193208

194209
assert.equal( "initial content", proto._handleDestination( "" ), "avoids manip" );
195210
} );
196211

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 ) {
198214
assert.equal( base + "#foo", proto._handleDestination( "#foo" ) );
199215
} );
200216

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 ) {
202219
assert.equal( "foo/bar", proto._handleDestination( "#foo/bar" ) );
203220
} );
204221

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

207230
QUnit.test( "does not record scroll position when disabled", function( assert ) {
208231
assert.expect( 0 );
@@ -215,7 +238,8 @@ QUnit.test( "does not record scroll position when disabled", function( assert )
215238
proto._recordScroll();
216239
} );
217240

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 ) {
219243
assert.expect( 1 );
220244

221245
var active = {};
@@ -238,7 +262,8 @@ QUnit.test( "prefers last scroll when it's larger than the minimum scroll", func
238262
assert.equal( active.lastScroll, 100, "should be equal to _getScroll value" );
239263
} );
240264

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 ) {
242267
assert.expect( 1 );
243268

244269
var active = {};
@@ -265,15 +290,18 @@ QUnit.test( "prefers default scroll when current scroll < default scroll", funct
265290

266291
QUnit.module( "Content Widget _find", {
267292
setup: function() {
293+
proto = reset;
294+
proto.element = $( "<div>" );
295+
reset = $.extend( {}, proto );
296+
268297
proto._getNs = function() {
269298
return "foo-";
270299
};
271-
272-
proto.element = $( "<div>" );
273300
}
274301
} );
275302

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 ) {
277305
this.element = $( "<div><div data-foo-url='bar'></div></div>" );
278306

279307
assert.equal(
@@ -283,7 +311,8 @@ QUnit.test( "returns the page container child matching the dataUrl first", funct
283311
);
284312
} );
285313

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 ) {
287316
var result;
288317

289318
proto.element = $( "<div><div id='bar'></div></div>" );
@@ -313,6 +342,9 @@ QUnit.test( "returns the first page when nothing matches", function( assert ) {
313342
QUnit.module( "Content Widget _parse", {
314343
setup: function() {
315344
$.mobile.ns = "foo-";
345+
proto = reset;
346+
proto.element = $( "<div>" );
347+
reset = $.extend( {}, proto );
316348
}
317349
} );
318350

@@ -338,7 +370,8 @@ QUnit.test( "returns first page with data role dialog", function( assert ) {
338370
assert.equal( page.attr( "data-foo-role" ), "dialog" );
339371
} );
340372

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 ) {
342375
var html, page;
343376

344377
html = "<body>foo</body>";
@@ -352,10 +385,14 @@ QUnit.test( "returns the body of the html wrapped in a page when no page exists"
352385
QUnit.module( "Content Widget _setLoadedTitle", {
353386
setup: function() {
354387
$.mobile.ns = "foo-";
388+
proto = reset;
389+
proto.element = $( "<div>" );
390+
reset = $.extend( {}, proto );
355391
}
356392
} );
357393

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 ) {
359396
var html, page, pageHtml;
360397

361398
pageHtml = "<div data-foo-role='page' data-foo-title='bar'></div>";
@@ -391,9 +428,16 @@ QUnit.test( "prevents injection", function( assert ) {
391428
assert.equal( page.jqmData( "title" ), undefined );
392429
} );
393430

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

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 ) {
397441
assert.expect( 4 );
398442

399443
proto.element.bind( "pagefoo", function( event, data ) {
@@ -409,7 +453,13 @@ QUnit.test( "triggers both content* and page* events and includes data", functio
409453
proto._triggerWithDeprecated( "foo", { bar: "baz" } );
410454
} );
411455

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

414464
QUnit.test( "include appends to the element", function( assert ) {
415465
var page = $( "<div>" );

0 commit comments

Comments
 (0)