mardi 19 juin 2018

Importing `constants` in Jest tests with named imports

I have a config and constants folder in my project. Located in src\config\test.ts & src\constants\index.js respectively.

I've setup Jest to use moduleNameMapper as below so I can just do import config from 'config' and import { SOME_CONST } from 'constants'

"moduleNameMapper": {
  "config$": "<rootDir>/src/config/test.js",
  "constants$": "<rootDir>/src/constants/index.js"
}

However, in my tests any files which use import { SOME_CONST } from 'constants' always get an undefined value for SOME_CONST whereas any which us the default export from config work fine.

Is this a known issue? Am I doing something wrong here? can't seem to pin it down.

Aucun commentaire:

Enregistrer un commentaire