mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	zjquery: Support empty find results.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							bb579742a2
						
					
				
				
					commit
					84b2952606
				
			@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user