loadable-components: TypeError: (0 , _component.default) is not a function mock tests
💬 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?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 20
@tejpowar how did you mock the loadable import?
Finally found rather simple solution which works for me without mocking:
LoadableComponent file:
Did anyone found any solution?
Hi,
We basically need to update unit tests whereby we are using loadable and need to mock it.
The error is:
Test suite failed to run
So the error is actually failing in our component when we run our unit tests.
Basically we need to mock out the above code within our unit test