Skip to content

Commit c3dfcf6

Browse files
committed
fixed event tests to trigger on a dom element
1 parent 7bf048a commit c3dfcf6

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

tests/unit/event/event_core.js

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@
1414
setup: function(){
1515

1616
// ensure bindings are removed
17-
$.each(events, function(i, name){
18-
$.each([$("#qunit-fixture"),
19-
$($.event.special.scrollstart),
20-
$($.event.special.tap),
21-
$($.event.special.tap),
22-
$($.event.special.swipe)], function(j, obj){
23-
obj.unbind(name);
24-
});
17+
$.each(events + "vmouseup vmousedown".split(" "), function(i, name){
18+
$("#qunit-fixture").unbind();
2519
});
2620

2721
//NOTE unmock
2822
Math.abs = absFn;
2923
$.Event.prototype.originalEvent = originalEventFn;
3024
$.Event.prototype.preventDefault = preventDefaultFn;
25+
$.Event.prototype.touches = [{pageX: 1, pageY: 1 }];
3126

3227
$($.mobile.pageContainer).unbind( "throttledresize" );
3328
}
@@ -43,7 +38,7 @@
4338
$.testHelper.reloadLib(libName);
4439

4540
$.each(events, function( i, name ) {
46-
ok($.fn[name] !== undefined, name + "is not undefined");
41+
ok($.fn[name] !== undefined, name + " is not undefined");
4742
});
4843
});
4944
});
@@ -88,40 +83,40 @@
8883
expect( 1 );
8984
$.event.special.scrollstart.enabled = false;
9085

91-
$($.event.special.scrollstart).bind("scrollstart", function(){
86+
$( "#qunit-fixture" ).bind("scrollstart", function(){
9287
ok(false, "scrollstart fired");
9388
});
9489

95-
$($.event.special.scrollstart).bind("touchmove", function(){
90+
$( "#qunit-fixture" ).bind("touchmove", function(){
9691
ok(true, "touchmove fired");
9792
start();
9893
});
9994

100-
$($.event.special.scrollstart).trigger("touchmove");
95+
$( "#qunit-fixture" ).trigger("touchmove");
10196
});
10297

10398
asyncTest( "scrollstart setup binds a function that triggers scroll start when enabled", function(){
10499
$.event.special.scrollstart.enabled = true;
105100

106-
$($.event.special.scrollstart).bind("scrollstart", function(){
101+
$( "#qunit-fixture" ).bind("scrollstart", function(){
107102
ok(true, "scrollstart fired");
108103
start();
109104
});
110105

111-
$($.event.special.scrollstart).trigger("touchmove");
106+
$( "#qunit-fixture" ).trigger("touchmove");
112107
});
113108

114109
asyncTest( "scrollstart setup binds a function that triggers scroll stop after 50 ms", function(){
115110
var triggered = false;
116111
$.event.special.scrollstart.enabled = true;
117112

118-
$($.event.special.scrollstart).bind("scrollstop", function(){
113+
$( "#qunit-fixture" ).bind("scrollstop", function(){
119114
triggered = true;
120115
});
121116

122117
ok(!triggered, "not triggered");
123118

124-
$($.event.special.scrollstart).trigger("touchmove");
119+
$( "#qunit-fixture" ).trigger("touchmove");
125120

126121
setTimeout(function(){
127122
ok(triggered, "triggered");
@@ -144,11 +139,11 @@
144139

145140
forceTouchSupport();
146141

147-
$($.event.special.tap).bind("taphold", function(){
142+
$( "#qunit-fixture" ).bind("taphold", function(){
148143
taphold = true;
149144
});
150145

151-
$($.event.special.tap).trigger("vmousedown");
146+
$( "#qunit-fixture" ).trigger("vmousedown");
152147

153148
setTimeout(function(){
154149
ok(taphold);
@@ -172,17 +167,17 @@
172167
mockAbs(100);
173168

174169
//NOTE record taphold event
175-
$($.event.special.tap).bind("taphold", function(){
170+
$( "#qunit-fixture" ).bind("taphold", function(){
176171
ok(false, "taphold fired");
177172
taphold = true;
178173
});
179174

180175
//NOTE start the touch events
181-
$($.event.special.tap).trigger("vmousedown");
176+
$( "#qunit-fixture" ).trigger("vmousedown");
182177

183178
//NOTE fire touchmove to push back taphold
184179
setTimeout(function(){
185-
$($.event.special.tap).trigger("vmousecancel");
180+
$( "#qunit-fixture" ).trigger("vmousecancel");
186181
}, 100);
187182

188183
//NOTE verify that the taphold hasn't been fired
@@ -203,11 +198,11 @@
203198
forceTouchSupport();
204199

205200
//NOTE record the tap event
206-
$($.event.special.tap).bind("tap", checkTap);
201+
$( "#qunit-fixture" ).bind("tap", checkTap);
207202

208-
$($.event.special.tap).trigger("vmousedown");
209-
$($.event.special.tap).trigger("vmouseup");
210-
$($.event.special.tap).trigger("vclick");
203+
$( "#qunit-fixture" ).trigger("vmousedown");
204+
$( "#qunit-fixture" ).trigger("vmouseup");
205+
$( "#qunit-fixture" ).trigger("vclick");
211206

212207
setTimeout(function(){
213208
start();
@@ -220,7 +215,7 @@
220215
forceTouchSupport();
221216

222217
//NOTE record tap event
223-
$($.event.special.tap).bind("tap", function(){
218+
$( "#qunit-fixture" ).bind("tap", function(){
224219
ok(false, "tap fired");
225220
tap = true;
226221
});
@@ -229,12 +224,12 @@
229224
mockAbs(100);
230225

231226
//NOTE start and move right away
232-
$($.event.special.tap).trigger("touchstart");
233-
$($.event.special.tap).trigger("touchmove");
227+
$( "#qunit-fixture" ).trigger("touchstart");
228+
$( "#qunit-fixture" ).trigger("touchmove");
234229

235230
//NOTE end touch sequence after 20 ms
236231
setTimeout(function(){
237-
$($.event.special.tap).trigger("touchend");
232+
$( "#qunit-fixture" ).trigger("touchend");
238233
}, 20);
239234

240235
setTimeout(function(){
@@ -248,7 +243,7 @@
248243

249244
forceTouchSupport();
250245

251-
$($.event.special.swipe).bind('swipe', function(){
246+
$( "#qunit-fixture" ).bind('swipe', function(){
252247
swipe = true;
253248
});
254249

@@ -257,15 +252,15 @@
257252
touches: false
258253
};
259254

260-
$($.event.special.swipe).trigger("touchstart");
255+
$( "#qunit-fixture" ).trigger("touchstart");
261256

262257
//NOTE make sure the coordinates are calculated within range
263258
// to be registered as a swipe
264259
mockAbs(opts.coordChange);
265260

266261
setTimeout(function(){
267-
$($.event.special.swipe).trigger("touchmove");
268-
$($.event.special.swipe).trigger("touchend");
262+
$( "#qunit-fixture" ).trigger("touchmove");
263+
$( "#qunit-fixture" ).trigger("touchend");
269264
}, opts.timeout + 100);
270265

271266
setTimeout(function(){
@@ -298,7 +293,7 @@
298293
forceTouchSupport();
299294

300295
// ensure the swipe custome event is setup
301-
$($.event.special.swipe).bind('swipe', function(){});
296+
$( "#qunit-fixture" ).bind('swipe', function(){});
302297

303298
//NOTE bypass the trigger source check
304299
$.Event.prototype.originalEvent = {
@@ -312,8 +307,8 @@
312307

313308
mockAbs(11);
314309

315-
$($.event.special.swipe).trigger("touchstart");
316-
$($.event.special.swipe).trigger("touchmove");
310+
$( "#qunit-fixture" ).trigger("touchstart");
311+
$( "#qunit-fixture" ).trigger("touchmove");
317312
});
318313

319314
asyncTest( "move handler returns when touchstart has been fired since touchstop", function(){
@@ -327,12 +322,12 @@
327322
forceTouchSupport();
328323

329324
// ensure the swipe custome event is setup
330-
$($.event.special.swipe).bind('swipe', function(){});
325+
$( "#qunit-fixture" ).bind('swipe', function(){});
331326

332-
$($.event.special.swipe).trigger("touchstart");
333-
$($.event.special.swipe).trigger("touchend");
327+
$( "#qunit-fixture" ).trigger("touchstart");
328+
$( "#qunit-fixture" ).trigger("touchend");
334329

335-
$($.event.special.swipe).bind("touchmove", function(){
330+
$( "#qunit-fixture" ).bind("touchmove", function(){
336331
ok(true, "touchmove bound functions are fired");
337332
start();
338333
});
@@ -341,7 +336,7 @@
341336
ok(false, "shouldn't compare coordinates");
342337
};
343338

344-
$($.event.special.swipe).trigger("touchmove");
339+
$( "#qunit-fixture" ).trigger("touchmove");
345340
});
346341

347342
var nativeSupportTest = function(opts){

0 commit comments

Comments
 (0)