diff --git a/frontend/util/__tests__/util_test.ts b/frontend/util/__tests__/util_test.ts index 3f0880b125..cf1e89ea47 100644 --- a/frontend/util/__tests__/util_test.ts +++ b/frontend/util/__tests__/util_test.ts @@ -3,6 +3,31 @@ import { times } from "lodash"; import { fakeTimeSettings } from "../../__test_support__/fake_time_settings"; describe("util", () => { + describe("scrollToBottom", () => { + it("returns early if element is not found", () => { + document.body.innerHTML = + "
" + + "
"; + jest.useFakeTimers(); + Util.scrollToBottom("wow"); + jest.runAllTimers(); + expect(setTimeout).toHaveBeenCalledTimes(0); + }); + + it("scrolls to bottom when an element is found", () => { + document.body.innerHTML = + "
" + + " " + + "
"; + jest.useFakeTimers(); + Util.scrollToBottom("wow"); + jest.runAllTimers(); + expect(setTimeout).toHaveBeenCalledTimes(1); + }); + }); + describe("safeStringFetch", () => { const data = { // tslint:disable-next-line:no-null-keyword diff --git a/frontend/util/util.ts b/frontend/util/util.ts index eed1b0059c..f403119225 100644 --- a/frontend/util/util.ts +++ b/frontend/util/util.ts @@ -172,7 +172,6 @@ export const timestamp = (date = new Date()) => Math.round(date.getTime()); export function scrollToBottom(elementId: string) { const elToScroll = document.getElementById(elementId); if (!elToScroll) { return; } - // Wait for the new element height and scroll to the bottom. setTimeout(() => elToScroll.scrollTop = elToScroll.scrollHeight, 1); }