dum3ng / study-issues

0 stars 0 forks source link

test typescript using jest #36

Closed dum3ng closed 4 years ago

dum3ng commented 4 years ago

install ts-jest

yarn add ts-jest

configure jest config

module.exports = {
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1',
    '^~/(.*)$': '<rootDir>/$1',
    '^vue$': 'vue/dist/vue.common.js',
  },
  moduleFileExtensions: ['js', 'vue', 'json', 'ts'],
  transform: {
    '^.+\\.(js|ts)$': '<rootDir>/node_modules/ts-jest/preprocessor.js', 
    '.*\\.(vue)$': 'vue-jest',
  },
}

Worth to notice is that moduleFileExtensions and transform:

add typescript support

yarn add -D @types/jest

then add the type definition in tsconfig.json:

{
  "types": ["jest"]
}

references