Jest beta Contributors are welcome

Installation

To begin, install Ts.ED testing module:

npm i -D @tsed/testing
1

Then install jest:

npm i -D jest ts-jest @types/jest
1

Configuration

Now you need to configure jest to work with Typescript. To do that crate a new file in your project root called jest.config.js and put the following configuration in it:

module.exports = {
    preset: "ts-jest",
    globals: {
        "ts-jest": {
            tsConfig: "tsconfig.json"
        }
    },
    verbose: true,
    collectCoverage: true,
    moduleFileExtensions: ["ts", "js", "json"],
    testMatch: ["**/tests/**/*.test.ts"],
    testEnvironment: "node",
    testPathIgnorePatterns: [
        "<rootDir>/node_modules/",
        "<rootDir>/out/"
    ],
    modulePathIgnorePatterns: [
        "<rootDir>/node_modules/",
        "<rootDir>/out/"
    ],
    coverageDirectory: "tests/result",
    collectCoverageFrom: [
        "src/controllers/**/*.ts",
        "src/middlewares/**/*.ts",
        "src/services/**/*.ts",
        "!**/*.d.ts"
    ]
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Important!!!

The DI will not work unless you set the TS_TEST environment variable to true like this:

{
    "scripts": {
        "test": "TS_TEST=true jest",
        "test:w": "TS_TEST=true jest --watch"
    }
}
1
2
3
4
5
6