Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not use resolve.alias for JEST testing

I am using WebPack + React + Jest for my application and I have set resolve.alias = { app: "/path/to/app" } in my configuration file.

In React, I can use this path to do require("app/component") and obtain the file at "/path/to/app/component.js" correctly.

When running JEST tests this alias is not recognized, neither in the tests, nor for the imported modules. All of this works when running the app but not the tests with jest-cli.

like image 970
gbbr Avatar asked Dec 22 '14 12:12

gbbr


1 Answers

jest-cli lives in a world separate from Webpack so it cannot work that way.

Use babel-plugin-module-resolver to handle aliasing.

like image 194
Juho Vepsäläinen Avatar answered Sep 17 '22 13:09

Juho Vepsäläinen