diff options
author | Sarah German <sgerman@gitlab.com> | 2023-07-21 20:18:01 +0300 |
---|---|---|
committer | Sarah German <sgerman@gitlab.com> | 2023-07-22 01:00:10 +0300 |
commit | 544526bce2e1a042dd0735f4e89bbbfcc49cbb65 (patch) | |
tree | 43eeb84f21a002e527dd75cad7c852636f954bfd | |
parent | 620607972811699d809332cf40601e1c7b34c594 (diff) |
Remove jQuery dependency from dom.jsjquery-domjs
https://youmightnotneedjquery.com/#outer_height
-rw-r--r-- | content/frontend/shared/dom.js | 8 | ||||
-rw-r--r-- | spec/frontend/default/components/collapsible_container_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/default/components/table_of_contents_spec.js | 2 |
3 files changed, 3 insertions, 9 deletions
diff --git a/content/frontend/shared/dom.js b/content/frontend/shared/dom.js index f4dbe540..618156d5 100644 --- a/content/frontend/shared/dom.js +++ b/content/frontend/shared/dom.js @@ -1,15 +1,9 @@ -/* global $ */ - /** * Returns outerHeight of element **even if it's hidden** * - * NOTE: Uses jQuery because there is no trivial way to do this in - * vaniall JS, and it's nice that jQuery has a reliable out-of-the-box - * solution. - * * @param {Element} el */ -export const getOuterHeight = (el) => $(el).outerHeight(); +export const getOuterHeight = (el) => el.offsetHeight; /** * Find the first child of the given element with the given tag name diff --git a/spec/frontend/default/components/collapsible_container_spec.js b/spec/frontend/default/components/collapsible_container_spec.js index 87395647..352b6797 100644 --- a/spec/frontend/default/components/collapsible_container_spec.js +++ b/spec/frontend/default/components/collapsible_container_spec.js @@ -17,7 +17,7 @@ describe('frontend/default/components/collapsible_container', () => { let wrapper; beforeEach(() => { - // jquery is not available in Jest yet so we need to mock this method + // Layout properties are not available in jsdom, so we need to mock this method jest.spyOn(dom, 'getOuterHeight').mockImplementation((x) => Number(x.dataset.testOuterHeight)); jest.useFakeTimers(); }); diff --git a/spec/frontend/default/components/table_of_contents_spec.js b/spec/frontend/default/components/table_of_contents_spec.js index 851258c3..64a738ef 100644 --- a/spec/frontend/default/components/table_of_contents_spec.js +++ b/spec/frontend/default/components/table_of_contents_spec.js @@ -19,7 +19,7 @@ describe('frontend/default/components/table_of_contents', () => { }); beforeEach(() => { - // jquery is not available in Jest yet so we need to mock this method + // Layout properties are not available in jsdom, so we need to mock this method jest.spyOn(dom, 'getOuterHeight').mockReturnValue(100); }); |