Files
dify/web/test/iframe.ts
T
dependabot[bot]andStephen Zhou f1aa8796bb chore(deps): bump happy-dom from 20.14.6 to 21.0.4 (#45501)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Stephen Zhou <hi@hyoban.cc>
2026-11-06 06:17:54 +00:00

20 lines
632 B
TypeScript

import { vi } from 'vite-plus/test'
/**
* Give each iframe a stable stand-in `contentWindow`, since happy-dom does not load iframe pages
* by default. Restore mocks after each test.
*/
export function stubIframeContentWindow() {
const windows = new WeakMap<HTMLIFrameElement, Window>()
return vi.spyOn(HTMLIFrameElement.prototype, 'contentWindow', 'get').mockImplementation(function (
this: HTMLIFrameElement,
) {
let frameWindow = windows.get(this)
if (!frameWindow) {
frameWindow = { postMessage: () => {} } as unknown as Window
windows.set(this, frameWindow)
}
return frameWindow
})
}