diff --git a/frontend_tests/node_tests/zjquery.js b/frontend_tests/node_tests/zjquery.js index 36ad716c68..3d37a4b0bf 100644 --- a/frontend_tests/node_tests/zjquery.js +++ b/frontend_tests/node_tests/zjquery.js @@ -90,6 +90,10 @@ run_test('finding_related_objects', () => { update_message_emoji('foo.png'); assert.equal(emoji.attr('src'), 'foo.png'); + // Sometimes you want to deliberatly test paths that do not find an + // element. You can pass 'false' as the result for those cases. + emoji.set_find_results('.random', false); + assert.equal(emoji.find('.random').length, 0); /* An important thing to understand is that zjquery doesn't truly simulate DOM. The way you make relationships work in zjquery diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 850ecd1a98..1467f46126 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -199,6 +199,12 @@ exports.make_new_elem = function (selector, opts) { if (child) { return child; } + if (child === false) { + // This is deliberately set to simulate missing find results. + // Return an empty array, the most common check is + // if ($.find().length) { //success } + return []; + } if (opts.silent) { return self; }