lingui / js-lingui

🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
https://lingui.dev
MIT License
4.67k stars 384 forks source link

Warning: React.jsx: type is invalid when running jest test #1227

Closed caobaloc12 closed 2 years ago

caobaloc12 commented 2 years ago

Describe the bug Getting this warning when using Trans component that is imported from @lingui/macro

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

To Reproduce

// ComponentA.tsx
// other imports
import { Trans } from "@lingui/macro";

export default function ComponentA() {
  return (
    <div><Trans>sample text</Trans></div>
   );
}

// ComponentA.test.tsx

// other imports
import ComponentA from "@/components/ComponentA";
jest.mock("@lingui/macro");

describe("Component A", () => {
 it("should render without crashing", () => {
    shallow(<ComponentA />);
 });
});

Expected behavior Should not get the warning message

Additional context If I change the import Trans component from @lingui/react the warning is gone

semoal commented 2 years ago

jest.mock("@lingui/macro");

You're mocking the entire library, what do you expect?