set up jest for your typescript project and how to import txt files in your unit tests

 

Getting Started

These instructions will get you setup to use ts-jest in your project. For more detailed documentation, please check online documentation.

using npmusing yarn
Prerequisitesnpm i -D jest typescriptyarn add --dev jest typescript
Installingnpm i -D ts-jest @types/jestyarn add --dev ts-jest @types/jest
Creating confignpx ts-jest config:inityarn ts-jest config:init
Running testsnpm t or npx jestyarn test or yarn jest


to import txt file as string, via jest-raw-loader

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
"transform": {
"\\.txt$": "jest-raw-loader"
}
};

or follow https://nextjs.org/docs/testing if you are using next.js


https://www.npmjs.com/package/jest-raw-loader

https://github.com/kulshekhar/ts-jest

https://jestjs.io/zh-Hans/docs/getting-started

https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object




Comments

Popular posts from this blog

react-native run-android : do not build/update modified code(App.js)

react-native run-android : sun.security.provider.cert path.SunCertPathBuilderException : unable to find valid certification path to req uested target

How to fix error : no module named sendgrid when try to use sendgrid python lib in PHP.