I assume that you’re here because of some test errors or whatnot that happen during each run. You suspect that the error is caused by the imported resource file(s) within the component, but not sure about the exact solution.

The obstacle

Basically, Jest can’t handle non-Javascript files by default, thereby all of these should also be mocked somehow.

Solution

Jest provides the moduleNameWrapper property that can be used in these non-regular cases. It accepts the following elements:

a RegEx that looks for all the files that match with it,

the mocking functionality that will be used instead of the matched files.

There are two approaches to mock out the resources — I’ll also demonstrate an example for each of them below:

with a 3rd-party package — for example identity-obj-proxy,

2. a simple, self-created file.