mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 19:59:21 +08:00
test: wrap test cleanup in act() to prevent window is not defined error (#31558)
Signed-off-by: majiayu000 <1835304752@qq.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { cleanup } from '@testing-library/react'
|
import { act, cleanup } from '@testing-library/react'
|
||||||
import { mockAnimationsApi, mockResizeObserver } from 'jsdom-testing-mocks'
|
import { mockAnimationsApi, mockResizeObserver } from 'jsdom-testing-mocks'
|
||||||
import '@testing-library/jest-dom/vitest'
|
import '@testing-library/jest-dom/vitest'
|
||||||
|
|
||||||
@@ -78,8 +78,13 @@ if (typeof globalThis.IntersectionObserver === 'undefined') {
|
|||||||
if (typeof Element !== 'undefined' && !Element.prototype.scrollIntoView)
|
if (typeof Element !== 'undefined' && !Element.prototype.scrollIntoView)
|
||||||
Element.prototype.scrollIntoView = function () { /* noop */ }
|
Element.prototype.scrollIntoView = function () { /* noop */ }
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(async () => {
|
||||||
cleanup()
|
// Wrap cleanup in act() to flush pending React scheduler work
|
||||||
|
// This prevents "window is not defined" errors from React 19's scheduler
|
||||||
|
// which uses setImmediate/MessageChannel that can fire after jsdom cleanup
|
||||||
|
await act(async () => {
|
||||||
|
cleanup()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// mock next/image to avoid width/height requirements for data URLs
|
// mock next/image to avoid width/height requirements for data URLs
|
||||||
|
|||||||
Reference in New Issue
Block a user