Diagnostics option

The diagnostics option allows to configure error reporting. It can both be enabled/disabled entirely or limited to a specific type of errors and/or files.

If a diagnostic is not filtered out, ts-jest will fail the compilation and your test.

Disabling/enabling

By default all diagnostics are enabled. This is the same as setting the diagnostics option to true. To disable all diagnostics, set diagnostics to false. This might lead to slightly better performance, especially if you’re not using Jest’s cache.

Advanced configuration

The option’s value can also accept an object for more advanced configuration. Each config. key is optional:

  • warnOnly: If specified and true, diagnostics will be reported but won’t stop compilation (default: disabled).
  • ignoreCodes: List of TypeScript error codes to ignore. Complete list can be found there. By default here are the ones ignored:
    • 6059: ‘rootDir’ is expected to contain all source files.
    • 18002: The ‘files’ list in config file is empty. (it is strongly recommended to include this one)
    • 18003: No inputs were found in config file.
  • pathRegex: If specified, diagnostics of source files which path does not match will be ignored.
  • pretty: Enables/disables colorful and pretty output of errors (default: enabled).

Examples

Disabling diagnostics

// jest.config.js
module.exports = {
  // [...]
  globals: {
    'ts-jest': {
      diagnostics: false
    }
  }
};
// OR package.json
{
  // [...]
  "jest": {
    "globals": {
      "ts-jest": {
        "diagnostics": false
      }
    }
  }
}

Advanced options

Enabling diagnostics for test files only

Assuming all your test files ends with .spec.ts or .test.ts, using the following config will enable error reporting only for those files:

// jest.config.js
module.exports = {
  // [...]
  globals: {
    'ts-jest': {
      diagnostics: {
        pathRegex: /\.(spec|test)\.ts$/
      }
    }
  }
};
// OR package.json
{
  // [...]
  "jest": {
    "globals": {
      "ts-jest": {
        "diagnostics": {
          "pathRegex": "\\.(spec|test)\\.ts$"
        }
      }
    }
  }
}
Do not fail on first error

While some diagnostics are stop-blockers for the compilation, most of them are not. If you want the compilation (and so your tests) to continue when encountering those, set the warnOnly to true:

// jest.config.js
module.exports = {
  // [...]
  globals: {
    'ts-jest': {
      diagnostics: {
        warnOnly: true
      }
    }
  }
};
// OR package.json
{
  // [...]
  "jest": {
    "globals": {
      "ts-jest": {
        "diagnostics": {
          "warnOnly": true
        }
      }
    }
  }
}
Ignoring some error codes

All TypeScript error codes can be found there. The ignoreCodes option accepts this values:

  1. A single number (example: 1009): unique error code to ignore
  2. A string with a code (example "1009", "TS1009" or "ts1009")
  3. A string with a list of the above (example: "1009, TS2571, 4072 ,ts6031 ")
  4. An array of one or more from 1 or 3 (example: [1009, "TS2571", "6031"])
// jest.config.js
module.exports = {
  // [...]
  globals: {
    'ts-jest': {
      diagnostics: {
        ignoreCodes: [2571, 6031, 18003]
      }
    }
  }
};
// OR package.json
{
  // [...]
  "jest": {
    "globals": {
      "ts-jest": {
        "diagnostics": {
          "ignoreCodes": [2571, 6031, 18003]
        }
      }
    }
  }
}