mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-03 12:26:05 +01:00 
			
		
		
		
	Bypass vitest bug (#32647)
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
				
			|||||||
import {createElementFromAttrs, createElementFromHTML, querySingleVisibleElem} from './dom.ts';
 | 
					import {createElementFromAttrs, createElementFromHTML, queryElemChildren, querySingleVisibleElem} from './dom.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test('createElementFromHTML', () => {
 | 
					test('createElementFromHTML', () => {
 | 
				
			||||||
  expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>');
 | 
					  expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>');
 | 
				
			||||||
@@ -26,3 +26,9 @@ test('querySingleVisibleElem', () => {
 | 
				
			|||||||
  el = createElementFromHTML('<div><span>foo</span><span>bar</span></div>');
 | 
					  el = createElementFromHTML('<div><span>foo</span><span>bar</span></div>');
 | 
				
			||||||
  expect(() => querySingleVisibleElem(el, 'span')).toThrowError('Expected exactly one visible element');
 | 
					  expect(() => querySingleVisibleElem(el, 'span')).toThrowError('Expected exactly one visible element');
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('queryElemChildren', () => {
 | 
				
			||||||
 | 
					  const el = createElementFromHTML('<div><span class="a">a</span><span class="b">b</span></div>');
 | 
				
			||||||
 | 
					  const children = queryElemChildren(el, '.a');
 | 
				
			||||||
 | 
					  expect(children.length).toEqual(1);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,6 +76,11 @@ export function queryElemSiblings<T extends Element>(el: Element, selector = '*'
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// it works like jQuery.children: only the direct children are selected
 | 
					// it works like jQuery.children: only the direct children are selected
 | 
				
			||||||
export function queryElemChildren<T extends Element>(parent: Element | ParentNode, selector = '*', fn?: ElementsCallback<T>): ArrayLikeIterable<T> {
 | 
					export function queryElemChildren<T extends Element>(parent: Element | ParentNode, selector = '*', fn?: ElementsCallback<T>): ArrayLikeIterable<T> {
 | 
				
			||||||
 | 
					  if (window.vitest) {
 | 
				
			||||||
 | 
					    // bypass the vitest bug: it doesn't support ":scope >"
 | 
				
			||||||
 | 
					    const selected = Array.from<T>(parent.children as any).filter((child) => child.matches(selector));
 | 
				
			||||||
 | 
					    return applyElemsCallback<T>(selected, fn);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  return applyElemsCallback<T>(parent.querySelectorAll(`:scope > ${selector}`), fn);
 | 
					  return applyElemsCallback<T>(parent.querySelectorAll(`:scope > ${selector}`), fn);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user