Skip to content

Latest commit

 

History

History
61 lines (41 loc) · 2.62 KB

README.md

File metadata and controls

61 lines (41 loc) · 2.62 KB

jest-runner-tsd

Run your TypeScript type tests using Jest.

version license

Note that since v2 the jest-runner-tsd is using tsd-lite instead of tsd. The type testing logic is the same in both implementations, i.e. both of them are wrapping around the TypeScript compiler to analyze types of your code.

Differences from tsd

The usage of tsd with monorepos written in TypeScript may become cumbersome, because of checks unrelated with types. tsd-light is an attempt to address these and similar issues.

Notable differences:

  • The tsd configuration in package.json is ignored. Please use jest.config to configure discovery of your test files and tsconfig.json to provide configuration for TS compiler.
  • The compiler configuration will be read from the nearest tsconfig.json for each test file. Hence, you may have a configuration for the whole project, or a group of test files, or just a particular test file.
  • tsd-lite will use the default TS compiler configuration without altering it. This means you should set "strict": true to use strict assertions, which are the default ones in vanilla tsd.
  • Only type testing is performed without any additional checks or rules.
  • The printType helper is discarded.

Install

yarn add -D jest-runner-tsd @tsd/typescript

Remember to install @tsd/typescript package. It is a required peer dependency.

Usage

  1. If your type tests live inside __typetests__ folders, set up jest.config.tsd.js like this:
module.exports = {
  displayName: {
    color: 'blue',
    name: 'types',
  },
  runner: 'jest-runner-tsd',
  testMatch: ['**/__typetests__/**/*.test.ts'],
};
  1. Add tsconfig.json to your project with configuration for TS compiler.

  2. Run yarn jest -c jest.config.tsd.js command or just include a script in package.json:

"scripts": {
  "test:types": "jest -c jest.config.tsd.js"
}

Tests

To learn more about tsd tests and assertions see the documentation.

License

MIT © Jest Community