Add mock for Element.scrollIntoView to fix tests.

Signed-off-by: Sydney Achinger <sydneynicoleachinger@spotify.com>
This commit is contained in:
Sydney Achinger
2023-10-16 15:52:41 -04:00
parent a7d5efa4a9
commit d0566f5184
2 changed files with 4 additions and 4 deletions
@@ -91,6 +91,8 @@ const configApi = new MockConfigApi({
},
});
Element.prototype.scrollIntoView = jest.fn();
const Wrapper = ({ children }: { children: React.ReactNode }) => {
return (
<TestApiProvider
@@ -86,10 +86,8 @@ export const TechDocsReaderPageContent = withTechDocsReaderProvider(
const [hashElement] = useShadowRootElements([`[id="${hash.slice(1)}"]`]);
useEffect(() => {
if (hashElement) {
if (!isStyleLoading) {
hashElement.scrollIntoView();
}
if (hashElement && !isStyleLoading) {
hashElement.scrollIntoView();
} else {
document?.querySelector('header')?.scrollIntoView();
}