How to use with Jest?
See original GitHub issueI’m trying to use your package with Jest to test React project but I can’t get it to work, below is my Jest configuration.
// jest.config.js
module.exports = {
// rest of config...
setupFilesAfterEnv: ['./tests/setup.ts']
};
// tests/setup.ts
import appRootPath from 'app-root-path';
import tsConfig from '../tsconfig.json';
import tsConfigPaths from 'tsconfig-paths';
let cleanup: () => void;
beforeAll(() => {
cleanup = tsConfigPaths.register({
baseUrl: appRootPath.path,
paths: tsConfig.compilerOptions.paths
});
});
afterAll(() => {
cleanup();
});
it keeps throwing errors like “Cannot find module ‘@views/components/error-boundary’ from ‘App.tsx’”
any ideas on how to use it with Jest, keep in mind that Jest doesn’t support the --require
flag.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
Getting Started - Jest
Install Jest using your favorite package manager: npm; Yarn. npm install --save-dev jest ... To use Babel, install required dependencies:.
Read more >Jest Tutorial for Beginners: Getting Started With JavaScript ...
Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package,...
Read more >Jest Tutorial - JavaScript Unit Testing Using Jest Framework
In this Jest tutorial, we will learn about various Jest features, Jest matchers and how to use Jest framework for JavaScript Unit Testing....
Read more >Testing TypeScript apps using Jest - LogRocket Blog
Jest is a simple, lightweight testing framework that provides a variety of testing capabilities to JavaScript and TypeScript projects. It ...
Read more >A Practical Guide To Testing React Applications With Jest
One thing we can do is to test components props — specifically, testing whether props from one component are being passed to another....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AhmedMKamal, you don’t need to use that package.
If you use the
baseUrl
andpaths
options in yourtsconfig
file, you must make sure to also configure themoduleNameMapper
option in your Jest config.tsconfig.json
jest.config.json
You’ll need to map the configuration to the Jest config format, which uses regular expressions.
ts-jest
provides a helper to transform the mapping fromtsconfig
to Jest config format, but it you use it you need the.js
version of the config file.jest.config.js
The module that you use basically does the same thing as the
pathsToModuleNameMapper
helper offered byts-jest
. But if you can usets-jest
’s helper, then I’d remove the extra dependency and use it instead.More information can be found here:
https://kulshekhar.github.io/ts-jest/user/config/
@geersch you can try to install
alias-hq
here’s the docs https://github.com/davestewart/alias-hq/blob/master/docs/integrations.md