question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest error: TypeError: React.forwardRef is not a function

See original GitHub issue

when start testing my app, I’m getting this error from Jest:

  ● Test suite failed to run

    TypeError: React.forwardRef is not a function

      21 | 
      22 |       for (var key in source) {
    > 23 |         if (Object.prototype.hasOwnProperty.call(source, key)) {
         |                             ^
      24 |           target[key] = source[key];
      25 |         }
      26 |       }

      at forwardRef (../../node_modules/@tippyjs/react/src/forwardRef.js:5:3)
      at ../../node_modules/@tippyjs/react/src/index.js:8:16
      at ../../node_modules/@tippyjs/react/dist/tippy-react.umd.js:2:66
      at Object.<anonymous> (../../node_modules/@tippyjs/react/dist/tippy-react.umd.js:5:2)

I’m using the Tippy version with props, is this a known issue?

thanks in advance!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
darbymanningcommented, May 11, 2021

@rafaelsorto I had this issue, so I ended up mocking the library in Jest, In case this is useful for anyone else:

jest.mock("@tippyjs/react", () => ({
  __esModule: true,
  default: jest.fn(),
}));
0reactions
rafaelsortocommented, Sep 28, 2021

I was able to solve my issue by mocking it as @JChiaramonte7 explained and it worked for me. Maybe your mocking is not actually overriding tippy ?

I somehow think it has to do with the project and jest settings because I created a new project trying to recreate this issue and I couldn’t. If you start a brand new create react app project and add @tippyjs/react with some tests it doesn’t complain. The issue I was having was specifically in a nextjs project where I manually configured jest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Component is not a function on adding forwardRef
The component is defined as below: import React from 'react'; import { forwardRef } from 'react' ...
Read more >
Forwarding Refs - React
Ref forwarding is a technique for automatically passing a ref through a component to one of its children. This is typically not necessary...
Read more >
How to use React's forwardRef function - Felix Gerschau
forwardRef is a helper function from React that allows us to forward a component's ref to another one. This tutorial will teach what...
Read more >
React Testing Library and the “not wrapped in act” Errors
…, unit test has no idea that advancing timers will cause component updates, and you will get the “not wrapped in act” error....
Read more >
Useful Patterns by Use Case - React TypeScript Cheatsheets
interface ButtonProps extends React. · : string; · } · export function Button(props: ButtonProps) { · const { specialProp, ... · // ERROR:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found