Skip to content

Instantly share code, notes, and snippets.

@clarkdave
Created February 7, 2012 11:38
Show Gist options
  • Save clarkdave/1759281 to your computer and use it in GitHub Desktop.
Save clarkdave/1759281 to your computer and use it in GitHub Desktop.
ZombieJS ignoring jQuery $.delegate
<!doctype html>
<html>
<head>
<title>ZombieJS test</title>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
</head>
<body>
<a href='#' id='clicker1'>Clicker one</a>
<a href='#' id='clicker2'>Clicker two</a>
<a href='#' id='clicker3'>Clicker three</a>
<script>
$(document).ready(function() {
$('#clicker1').bind('click', function() {
console.log('Clicked one');
});
$('body').delegate('#clicker2', 'click', function() {
console.log('Clicked two');
});
// preferred way to do delegation in jQuery 1.7+
$('body').on('click', '#clicker3', function() {
console.log('Clicked three');
})
});
</script>
</body>
</html>
var Zombie = require('zombie');
var browser = new Zombie();
browser.visit('http://localhost:8000', function() {
browser.clickLink('Clicker one', function() {
console.log('--> Callback fired for clicker one');
browser.clickLink('Clicker two', function() {
console.log('--> Callback fired for clicker two');
browser.clickLink('Clicker three', function() {
console.log('--> Callback fired for clicker three');
});
});
});
});
@clarkdave
Copy link
Author

In a browser, all three links in the index.html will fire when clicked.

In the supplied ZombieJS test, only the first one (a direct bind) will actually fire. The other two will have their clickLink callbacks executed within Node but they won't actually fire their browser callbacks (i.e. the only console.log statement to appear is that of the first link).

@michelsalib
Copy link

Hi clack, where can I track the status of this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment