Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Mocking a Util function that requires a React Dom node

I have this util function that scrolls into view that I'm trying to test. The function (below) checks for a react dom node. I can't seem to figure out in jest how to test this function by providing the Dom node.

export const scrollIntoView = (node, behavior, block) => {
  if (!node) return;
  const element = ReactDom.findDOMNode(node);
  try {
    if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
      if ("parentIFrame" in window) {
        window.parentIFrame.scrollToOffset(0, 0);
      } else {
        window.scrollTo({ top: 0, behavior: behavior || "smooth" });
      }
    } else {
      element.scrollIntoView({
        behavior: behavior || "smooth",
        block: block || "start",
      });
    }
  } catch (error) {
    element.scrollIntoView(false);
  }
};

Here is my test: When I do the following I get the error: Argument appears to not be a ReactComponent.

it("Should scroll up", () => {
    const mockScrollIntoView = jest.fn(scrollIntoView);
    const node = (document.body.innerHTML = '<App id="root"/>');

    mockScrollIntoView(node);
    expect(mockScrollIntoView).toBeCalledWith({
      behavior: "smooth",
      block: "start",
    });
  });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!