Skip to content

Commit c3c49e6

Browse files
authored
test(amazonq): add mock for IntersectionObserver (#6867)
## Problem `ReferenceError: IntersectionObserver is not defined` in E2E tests due to JSDOM ## Solution Add mock for IntersectionObserver --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f0e16c4 commit c3c49e6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/amazonq/test/e2e/amazonq/framework/jsdomInjector.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ export function injectJSDOM() {
4747

4848
// jsdom doesn't have support for structuredClone. See https://github.com/jsdom/jsdom/issues/3363
4949
global.structuredClone = (val: any) => JSON.parse(JSON.stringify(val))
50+
51+
global.IntersectionObserver = class IntersectionObserver {
52+
observe() {}
53+
unobserve() {}
54+
disconnect() {}
55+
takeRecords() {
56+
return []
57+
}
58+
// eslint-disable-next-line unicorn/no-null
59+
root = null
60+
rootMargin = ''
61+
thresholds = []
62+
}
5063
}

0 commit comments

Comments
 (0)