diff --git a/packages/core/src/components/HorizontalScrollGrid/HorizontalScrollGrid.test.jsx b/packages/core/src/components/HorizontalScrollGrid/HorizontalScrollGrid.test.tsx similarity index 79% rename from packages/core/src/components/HorizontalScrollGrid/HorizontalScrollGrid.test.jsx rename to packages/core/src/components/HorizontalScrollGrid/HorizontalScrollGrid.test.tsx index 83cec85fc5..b75b28700d 100644 --- a/packages/core/src/components/HorizontalScrollGrid/HorizontalScrollGrid.test.jsx +++ b/packages/core/src/components/HorizontalScrollGrid/HorizontalScrollGrid.test.tsx @@ -48,6 +48,8 @@ describe('', () => { }); it('should show scroll buttons', async () => { + const originalPrototype = HTMLElement.prototype; + Object.defineProperties(HTMLElement.prototype, { scrollLeft: { configurable: true, @@ -64,13 +66,13 @@ describe('', () => { }); let lastScroll = 0; - HTMLElement.prototype.scrollBy = ({ left }) => { - lastScroll = left; + HTMLElement.prototype.scrollBy = ({ left }: ScrollToOptions): void => { + lastScroll = left || 0; }; const rendered = await renderWithEffects( wrapInTestApp( - + item1 @@ -89,9 +91,21 @@ describe('', () => { fireEvent.click(rendered.getByTitle('Scroll Left')); expect(lastScroll).toBeLessThan(0); - delete HTMLElement.prototype.scrollLeft; - delete HTMLElement.prototype.offsetWidth; - delete HTMLElement.prototype.scrollWidth; - delete HTMLElement.prototype.scrollBy; + // reset to original values + Object.defineProperties(HTMLElement.prototype, { + scrollLeft: { + configurable: true, + value: originalPrototype.scrollLeft, + }, + offsetWidth: { + configurable: true, + value: originalPrototype.offsetWidth, + }, + scrollWidth: { + configurable: true, + value: originalPrototype.scrollWidth, + }, + }); + HTMLElement.prototype.scrollBy = originalPrototype.scrollBy; }); });