Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

jest aliases typescript storybook

// tsconfig.json
{
 ...
 "baseUrl": "src",
 "paths": {
    "@alias/*": [ 'path/to/alias/*' ]
 }
 ...
}

//then your jest.config.js needs to provide those paths in moduleNameMapper in the following format:
// jest.config.js
module.exports = {
    'roots': [
        '<rootDir>/src'
    ],
    'transform': {
        '^.+.tsx?$': 'ts-jest'
    },
    'moduleNameMapper': {
         '@alias/(.*)': '<rootDir>/src/path/to/alias/$1'
    }
};

//Example tsconfig.json
{
	"baseUrl": "./",
	"paths": {
      "@/*": ["src/*"],
    },
}

//Example jest.config.json
"moduleNameMapper": {
  "@/(.*)": "<rootDir>/src/$1",
}
 
PREVIOUS NEXT
Tagged: #jest #aliases #typescript #storybook
ADD COMMENT
Topic
Name
2+4 =