An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
May 12, 2022 01:02 am GMT
Original Link: https://dev.to/tylim88/jest-typescript-minus-ts-jest-38ic
Jest Typescript minus TS-Jest
ts-jest
is a popular package when you try to use typescript
with jest
.
But one issue that is bugging me recently is, the uncovered lines stat is not correct, my test coverage dropped by 10+%.
After googling, nothing useful come up, and after some troubleshooting, I found out that it was ts-jest
that causing the issue
so I decided to use babel for compilation instead
install dependencies
npm i -D @babel/preset-env @babel/preset-typescript typescript jest
setup npm script
"scripts": { "test": "jest",}
create a jest.config.js
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */module.exports = { testEnvironment: 'node', roots: ['<rootDir>/src'], testMatch: ['**/__tests__/**/*.+(ts|js)', '**/?(*.)+(spec|test).+(ts|js)'], transform: { '^.+\\.(js|ts)$': 'babel-jest', }, moduleDirectories: ['node_modules', 'src'], collectCoverage: true, collectCoverageFrom: ['**/*.{js,ts}', '!**/*.d.ts'],}
create a babel.config.js
module.exports = { presets: [ '@babel/preset-typescript', [ '@babel/preset-env', { targets: { node: 'current', }, }, ], ],}
you don't need to install babel-jest
, it comes with jest
finally npm test
and boom, your 100% test coverage is back.
Original Link: https://dev.to/tylim88/jest-typescript-minus-ts-jest-38ic
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To