Skip to content

moduleNameMapper does not work with constants #8610

Closed
@maksimsemenov

Description

@maksimsemenov

🐛 Bug Report

When I'm trying to use moduleNameMapper to resolve import from constants local folder, it does not work. It works fine, when I use singular form: constant.
I think it might happen because constants is sort of reserved module in node.js. However, plural form (constants) works fine with web pack aliases, so they find a workaround somehow.

To Reproduce

In one of the files import variable from constants module:

import { A_CONSTANT } from 'constants'

Set up an alias with moduleNameMapper:

"moduleNameMapper": {
      "^constants$": "<rootDir>/src/constants/index.js"
    }

Run tests

Expected behavior

The variable should be defined. Instead it is undefined

Link to repl or repo (highly encouraged)

https://github.com/maksimsemenov/jest-module-name-mapper

Run npx envinfo --preset jest

System:
    OS: macOS 10.14.5
    CPU: (4) x64 Intel(R) Core(TM) i5-4260U CPU @ 1.40GHz
  Binaries:
    Node: 10.15.3 - /opt/local/bin/node
    Yarn: 1.15.2 - /opt/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions