You can tell Jest how to resolve module paths by configuring the moduleNameMapper option, which is useful if you’re using packages like module-alias or if you’re using absolute paths. Add these lines to your Jest configuration:
{
// ...
"jest": {
// ...
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
}
}
Now modules that start with src/
will be looked into <rootDir>/
, which is the src
folder by default (this configured a few lines above). Check out the documentation link above to get ideas of everything you can do with this.
I don’t know what’s wrong with using absolute paths as the other reply said, it’s not only useful but it also works just fine in both NestJS and in Angular.