zjquery: Support empty find results.

This commit is contained in:
Rohitt Vashishtha 2020-05-21 08:49:57 +05:30 committed by Tim Abbott
parent bb579742a2
commit 84b2952606
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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;
}