Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make a DOM test simulate a click instead of triggering a custom event.

  • Loading branch information...
commit 87b2fda4991f2f08c68d96bc1c111aa28818aa8f 1 parent 78082ec
Andrew Dupont authored November 15, 2010

Showing 1 changed file with 21 additions and 4 deletions. Show diff stats Hide diff stats

  1. 25  test/unit/dom_test.js
25  test/unit/dom_test.js
@@ -7,6 +7,18 @@ var createParagraph = function(text) {
7 7
   return p;
8 8
 }
9 9
 
  10
+function simulateClick(node) {
  11
+  var oEvent;
  12
+  if (document.createEvent) {
  13
+    oEvent = document.createEvent('MouseEvents');
  14
+    oEvent.initMouseEvent('click', true, true, document.defaultView,
  15
+     0, 0, 0, 0, 0, false, false, false, false, 0, node);
  16
+    node.dispatchEvent(oEvent);
  17
+  } else {
  18
+    node.click();
  19
+  }
  20
+}
  21
+
10 22
 new Test.Unit.Runner({
11 23
   setup: function() {
12 24
     if (documentViewportProperties) return;
@@ -1550,15 +1562,20 @@ new Test.Unit.Runner({
1550 1562
     child.store('foo', 'bar');
1551 1563
     
1552 1564
     var trigger = false;    
1553  
-    child.observe('test:event', function(event) { trigger = true; });
  1565
+    child.observe('click', function(event) { trigger = true; });
1554 1566
     var childUID = child._prototypeUID;
1555 1567
 
1556 1568
     parent.update("");
1557 1569
 
1558 1570
     // At this point, `child` should have been purged.
1559  
-    this.assert(!(childUID in Element.Storage), "purged element's UID should no longer exist in `Element.Storage`");
1560  
-
1561  
-    var event = child.fire('test:event');
  1571
+    this.assert(
  1572
+      !(childUID in Element.Storage), 
  1573
+      "purged element's UID should no longer exist in `Element.Storage`"
  1574
+    );
  1575
+    
  1576
+    // Simulate a click to be sure the element's handler has been
  1577
+    // unregistered.
  1578
+    simulateClick(child);
1562 1579
     this.assert(!trigger, "fired event should not have triggered handler");
1563 1580
   }
1564 1581
 });

0 notes on commit 87b2fda

Please sign in to comment.
Something went wrong with that request. Please try again.