test: use happy dom (#34154)

This commit is contained in:
Stephen Zhou
2026-03-27 09:46:19 +08:00
committed by GitHub
parent 368896d84d
commit 07f4950cb3
33 changed files with 306 additions and 157 deletions

View File

@ -11,7 +11,7 @@ describe('code.tsx components', () => {
vi.clearAllMocks()
vi.spyOn(console, 'error').mockImplementation(() => {})
vi.useFakeTimers({ shouldAdvanceTime: true })
// jsdom does not implement scrollBy; mock it to prevent stderr noise
// The test DOM runtime does not implement scrollBy; mock it to prevent stderr noise
window.scrollBy = vi.fn()
})

View File

@ -307,7 +307,7 @@ describe('useDocToc', () => {
it('should update activeSection when scrolling past a section', async () => {
vi.useFakeTimers()
// innerHeight/2 = 384 in jsdom (default 768), so top <= 384 means "scrolled past"
// innerHeight/2 = 384 with the default test viewport height (768), so top <= 384 means "scrolled past"
const { scrollContainer, cleanup } = setupScrollDOM([
{ id: 'intro', text: 'Intro', top: 100 },
{ id: 'details', text: 'Details', top: 600 },