mirror of
https://github.com/langgenius/dify.git
synced 2026-11-11 05:41:09 +08:00
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>
20 lines
632 B
TypeScript
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
|
|
})
|
|
}
|