diff --git a/frontend_tests/node_tests/zjquery.js b/frontend_tests/node_tests/zjquery.js index 10fe008834..14a41e9a60 100644 --- a/frontend_tests/node_tests/zjquery.js +++ b/frontend_tests/node_tests/zjquery.js @@ -135,8 +135,13 @@ run_test('events', () => { var value; function initialize_handler() { - $('#my-parent').on('input', '.some-child-class', function (e) { - value = 42; // just a dummy side effect + $('#my-parent').on('click', '.button-red', function (e) { + value = 'red'; // just a dummy side effect + e.stopPropagation(); + }); + + $('#my-parent').on('click', '.button-blue', function (e) { + value = 'blue'; e.stopPropagation(); }); } @@ -147,7 +152,7 @@ run_test('events', () => { // We want to call the inner function, so first let's get it using the // get_on_handler() helper from zjquery. - var handler_func = $('#my-parent').get_on_handler('input', '.some-child-class'); + var red_handler_func = $('#my-parent').get_on_handler('click', '.button-red'); // Set up a stub event so that stopPropagation doesn't explode on us. var stub_event = { @@ -155,10 +160,15 @@ run_test('events', () => { }; // Now call the hander. - handler_func(stub_event); + red_handler_func(stub_event); // And verify it did what it was supposed to do. - assert.equal(value, 42); + assert.equal(value, 'red'); + + // Test we can have multiple click handlers in the parent. + var blue_handler_func = $('#my-parent').get_on_handler('click', '.button-blue'); + blue_handler_func(stub_event); + assert.equal(value, 'blue'); }); run_test('create', () => { diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 3f4d10eacb..d27ce95d14 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -35,11 +35,13 @@ exports.make_event_store = (selector) => { get_on_handler: function (name, child_selector) { var funcs = self.get_on_handlers(name, child_selector); + var handler_name = name + ' with ' + child_selector; if (funcs.length === 0) { - throw Error('Could not find handler for ' + name); + throw Error('Could not find handler for ' + handler_name); } if (funcs.length > 1) { - throw Error('Found too many handlers for ' + name); + var remedy = "\nMaybe clear zjquery between tests?"; + throw Error('Found too many handlers for ' + handler_name + remedy); } return funcs[0]; },