Skip to content

Commit

Permalink
BraidTestProvider: Provide scrollIntoView stub function for jsdom (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltaranto authored Sep 19, 2024
1 parent f1fe217 commit 819c667
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .changeset/bright-squids-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'braid-design-system': patch
---

---
updated:
- BraidTestProvider
---

**BraidTestProvider:** Provide `scrollIntoView` stub function for jsdom

Fixes an issue where `scrollIntoView` is not defined in jsdom, causing tests to fail with the following error:
```
Error: Uncaught [TypeError: highlightedItem?.scrollIntoView is not a function]
```
3 changes: 0 additions & 3 deletions jest/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { format, TextEncoder, TextDecoder } from 'util';
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;

// Mocking for `jsdom`
window.HTMLElement.prototype.scrollIntoView = function () {};

const error = global.console.error;

globalThis.IS_REACT_ACT_ENVIRONMENT = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import {
import { BraidTestProviderContext } from './BraidTestProviderContext';
import { breakpointContext } from '../BraidProvider/BreakpointContext';

/**
* Mocking for `jsdom` which doesn't support `scrollIntoView`.
* Can remove this if/when `jsdom` adds a stub for `scrollIntoView`.
*
* GitHub issue: https://github.com/jsdom/jsdom/issues/1695
* Pull request: https://github.com/jsdom/jsdom/pull/3639
*/
if (
typeof navigator !== 'undefined' &&
navigator?.userAgent?.includes('jsdom')
) {
window.HTMLElement.prototype.scrollIntoView =
window.HTMLElement.prototype.scrollIntoView || (() => {});
}

interface BraidTestProviderProps
extends Omit<BraidProviderProps, 'theme' | 'styleBody'> {
themeName?: keyof typeof themes;
Expand Down

0 comments on commit 819c667

Please sign in to comment.