This tutorial is part 2 of 2 in the series.
Here you will learn how to use Jest with Babel Module Resolver for aliases that are defined in your .babelrc file:
{..."plugins": [["module-resolver",{"root": ["./"],"alias": {"@components": "./src/components","@constants": "./src/constants",}}],]}
In order to get the same alias mappings to Jest, the jest.config.js file needs to look like this:
module.exports = {roots: ['<rootDir>'],moduleFileExtensions: ['js', 'ts', 'tsx', 'json'],testPathIgnorePatterns: ['./node_modules/'],moduleNameMapper: {'^@components(.*)$': '<rootDir>/src/components$1','^@constants(.*)$': '<rootDir>/src/constants$1',},testEnvironment: 'jsdom',transform: {'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',},};
Now you can use import statemes with aliases in your Jest testing environment too.