Skip to content

Commit c6c82f4

Browse files
committed
chore: move scrollTo to jsdom-extra-mocks-register
1 parent 00ccee3 commit c6c82f4

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

configs/mocha-config-compass/register/jsdom-extra-mocks-register.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ globalThis.CustomEvent = window.CustomEvent;
5151
globalThis.Event = window.Event;
5252
globalThis.Blob = window.Blob;
5353
globalThis.File = window.File;
54+
55+
// jsdom doesn't support scrollTo on the Element, so make it a no-op
56+
globalThis.Element.prototype.scrollTo = () => {};

configs/webpack-config-compass/src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,23 @@ export function createElectronRendererConfig(
279279
overlay:
280280
process.env.DISABLE_DEVSERVER_OVERLAY === 'true'
281281
? false
282-
: { warnings: false, errors: true, runtimeErrors: true },
282+
: {
283+
runtimeErrors: (error) => {
284+
// ResizeObserver errors are harmless and expected in some cases.
285+
// We currently get them when opening the Assistant drawer.
286+
if (
287+
error?.message ===
288+
'ResizeObserver loop completed with undelivered notifications.'
289+
) {
290+
// eslint-disable-next-line no-console
291+
console.warn(error);
292+
return false;
293+
}
294+
return true;
295+
},
296+
errors: true,
297+
warnings: false,
298+
},
283299
},
284300
https: false,
285301
hot: opts.hot,

packages/compass-assistant/src/assistant-chat.spec.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import {
77
} from '@mongodb-js/testing-library-compass';
88
import { AssistantChat } from './assistant-chat';
99
import { expect } from 'chai';
10-
import { createMockChat, withMockedScrollTo } from '../test/utils';
10+
import { createMockChat } from '../test/utils';
1111
import type { AssistantMessage } from './compass-assistant-provider';
1212

1313
describe('AssistantChat', function () {
14-
withMockedScrollTo();
15-
1614
let originalScrollTo: typeof Element.prototype.scrollTo;
1715
// Mock scrollTo method for DOM elements to prevent test failures
1816
before(function () {

packages/compass-assistant/src/compass-assistant-provider.spec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '@mongodb-js/compass-components';
2323
import type { AtlasService } from '@mongodb-js/atlas-service/provider';
2424
import { CompassAssistantDrawer } from './compass-assistant-drawer';
25-
import { createMockChat, withMockedScrollTo } from '../test/utils';
25+
import { createMockChat } from '../test/utils';
2626

2727
// Test component that renders AssistantProvider with children
2828
const TestComponent: React.FunctionComponent<{
@@ -85,7 +85,6 @@ describe('AssistantProvider', function () {
8585
});
8686

8787
describe('with existing chat instance', function () {
88-
withMockedScrollTo();
8988
before(function () {
9089
// TODO(COMPASS-9618): skip in electron runtime for now, drawer has issues rendering
9190
if ((process as any).type === 'renderer') {

packages/compass-assistant/test/utils.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,3 @@ export const createMockChat = ({
1515
sendMessage: sinon.SinonStub;
1616
};
1717
};
18-
19-
export function withMockedScrollTo() {
20-
let originalScrollTo: typeof Element.prototype.scrollTo;
21-
// Mock scrollTo method for DOM elements to prevent test failures
22-
before(function () {
23-
originalScrollTo = Element.prototype.scrollTo;
24-
if (!Element.prototype.scrollTo) {
25-
Element.prototype.scrollTo = () => {};
26-
}
27-
});
28-
after(function () {
29-
Element.prototype.scrollTo = originalScrollTo;
30-
});
31-
}

0 commit comments

Comments
 (0)