Skip to content

Instantly share code, notes, and snippets.

@bustardcelly
Created January 29, 2014 14:50
Show Gist options
  • Save bustardcelly/8689593 to your computer and use it in GitHub Desktop.
Save bustardcelly/8689593 to your computer and use it in GitHub Desktop.
zombiejs patch for non-trapping of link event to allow for bubble up when using SAP libraries.
/**
* We are using page.js for client routing.
* We are using zombie.js as a headless browser during testing.
*
* zombie.js traps the click event of an A element and prevents it from bubbling up to the window.
* page.js listens for 'click' on window to determine location routing.
*
* As such, they conflict and setup for changing location within a SAP within a test will return a 404.
* Load this in as a patch for zombie within a feature module that requires a change to the location.
*/
var HTML = require(process.cwd() + "/node_modules/zombie/node_modules/jsdom").dom.level3.html;
HTML.HTMLAnchorElement.prototype._eventDefaults = {
click: function(event) {
var anchor, browser, window;
anchor = event.target;
if (!anchor.href) {
return;
}
window = anchor.ownerDocument.window;
event.which = 1;
window.dispatchEvent(event);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment