Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Jest: custom moduleNameMapper entries should have priority #1650

Closed
davidje13 opened this issue Nov 22, 2020 · 0 comments
Closed

Jest: custom moduleNameMapper entries should have priority #1650

davidje13 opened this issue Nov 22, 2020 · 0 comments

Comments

@davidje13
Copy link
Contributor

When custom moduleNameMapper config is provided, it ends up at the bottom of the list, below automatic configuration for static file types (stylesheets / images). This causes problems when mocking out more complex interpretations of these file types (e.g. SVGR creates additional exports for SVG files).

For example:

    jest({
      moduleNameMapper: {
        '\\.svg$': '<rootDir>/mocks/svgr.js',
      },
    }),

Where svgr.js contains:

export const ReactComponent = () => null;
export default '';

The given config is ignored, because the built-in SVG rule takes priority (using file-mock).


This could be fixed by putting user-specified moduleNameMapper entries at the top of the resulting config, rather than the bottom. I think it is reasonable for anything the user specifies to override the defaults.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant