mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-20 16:18:08 +00:00
test: run frontend unit tests in browsers (#38860)
Run them in headless [vitest browser mode](https://vitest.dev/guide/browser/) in chromium and firefox. Similar UX than current tests, it's about 5 times as slow (goes from 1s to 5s on my machine), but definitely worth it as it removes all happy-dom problems. --------- Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -26,15 +26,16 @@ test('createElementFromAttrs', () => {
|
||||
});
|
||||
|
||||
test('querySingleVisibleElem', () => {
|
||||
let el = createElementFromHTML('<div></div>');
|
||||
const el = document.createElement('div');
|
||||
document.body.append(el); // layout, and thus visibility, is only computed in the document
|
||||
expect(querySingleVisibleElem(el, 'span')).toBeNull();
|
||||
el = createElementFromHTML('<div><span>foo</span></div>');
|
||||
el.innerHTML = '<span>foo</span>';
|
||||
expect(querySingleVisibleElem(el, 'span')!.textContent).toEqual('foo');
|
||||
el = createElementFromHTML('<div><span style="display: none;">foo</span><span>bar</span></div>');
|
||||
el.innerHTML = '<span style="display: none;">foo</span><span>bar</span>';
|
||||
expect(querySingleVisibleElem(el, 'span')!.textContent).toEqual('bar');
|
||||
el = createElementFromHTML('<div><span class="some-class tw-hidden">foo</span><span>bar</span></div>');
|
||||
el.innerHTML = '<span class="some-class tw-hidden">foo</span><span>bar</span>';
|
||||
expect(querySingleVisibleElem(el, 'span')!.textContent).toEqual('bar');
|
||||
el = createElementFromHTML('<div><span>foo</span><span>bar</span></div>');
|
||||
el.innerHTML = '<span>foo</span><span>bar</span>';
|
||||
expect(() => querySingleVisibleElem(el, 'span')).toThrow('Expected exactly one visible element');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user