« All posts

02.06.2022 - Typescript / Testing with Jest

To use Jest for testing a TypeScript library, we need to install a couple of things:

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

And set up the jest.config.ts file to use the ts-jest transformer when processing *.test.ts files:

import type { Config } from '@jest/types';
 
const config: Config.InitialOptions = {
    verbose: true,
    transform: {
        '^.+\\.ts?$': 'ts-jest',
    }
};
 
export default config;

From now on, you can run jest command to start testing every *.test.ts file in the project.

"scripts": {
    "build": "parcel build",
    "test": "jest"
},

Read more