How to test ts files with jest

see the instructions on jest"s official website to download ts-jest, but I don"t know how to use it, and no clear tutorials have been found. Please help me

Feb.28,2021

first step to install the package:

yarn add -D typescript jest ts-jest @types/jest

step 2: initialize project-related configuration files:
generate tsconfig.json:

tsc --init

create jest.config.js:

module.exports = {
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}

directory structure:

clipboard.png

base.spec.ts:


:

clipboard.png

Menu