TypeError: (0 , _component.default) is not a function mock tests

See original GitHub issue

💬 Questions and Help

Hi,

We are using the loadable/component function to load components but are having issues with the mocking tests and running into the following error:

TypeError: (0 , _component.default) is not a function

Within our test we have just created a mock like so

jest.mock('@loadable/component', () => ({
  loadable: jest.fn()
}));

Also tried

jest.mock('@loadable/component', () => {
  const original = jest.requireActual('@loadable/component');
  return {
    ...original,
    __esModule: true,
    default: () => {},
    loadableReady: callback => callback(),
  };
});

But this still errors.

Any ideas on how we can mock it?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:15

github_iconTop GitHub Comments

2reactions
nathanmillar16commented, Jul 3, 2022

@tejpowar how did you mock the loadable import?

1reaction
tara-singh-danucommented, Jun 22, 2022

Did anyone found any solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest failing with TypeError: (0 , _user.default) is not a function
I've tried mocking the getUserInfo() other ways and it still fails. What is wrong here? I'm thinking it has something to do with...
Read more >
Jest failing with TypeError: (0 , _user.default) is not a function ...
I had this same problem and I solved it doing: jest.mock('../src/services/user', () => ({ __esModule: true, default: () => Promise.resolve({ ...
Read more >
Bypassing module mocks - Jest
Jest allows you to mock out whole modules in your tests, ... throwing the error: TypeError: response.text is not a function .
Read more >
Unit tests - Mattermost Developers
If you get an error like UnhandledPromiseRejectionWarning: TypeError: (0 , \_fff.hhh) is not a function. Check if you're mocking part of an imported...
Read more >
(0 , dayjs_1.default) is not a function - You.com - You.com
max method existed, but the test suite only imported the component and not its parent, therefore the plugin wasn't being applied to dayjs....
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