Testing
Setting up Jest with TypeScript
$ cd packages/api
$ mkdir src
$ mv index.ts srcmodule.exports = {
preset: 'ts-jest',
rootDir: 'src',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testEnvironment: 'node',
moduleFileExtensions: ['js', 'ts', 'tsx'],
moduleDirectories: ['node_modules'],
coverageReporters: ['html'],
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json',
},
},
};Writing tests
Mocking dependencies is hard
Dependencies injection
Containers file
Code coverage



Why do we even write test?
It is documentation
If it can break, it will break
It can be part of the debugging process
Refactoring becomes easier
To test or not to test
Last updated