Package Exports
- jest-tsd
- jest-tsd/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jest-tsd) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Jest TSD
The easiest way to test your TS types with Jest.
Install
# Install with npm
npm i -D jest-tsd @tsd/typescript
# Or install with yarn
yarn add --dev jest-tsd @tsd/typescriptNote:
@tsd/typescriptwill be used to compile your type tests. If you have compiling issues, adjust its version to match the version oftypescriptyou have installed.
Setup
Create a type definition test file
.test-d.tsin the same directory with the same name as your Jest test filee.g. If your Jest test is located at
src/dir/foo.test.js, create asrc/dir/foo.test-d.tsfileIn your type definition test you can import the assertion functions from
jest-tsdimport { expectType } from 'jest-tsd';
Add a test to your Jest test file
import { expectTypeTestsToPassAsync } from 'jest-tsd'; it('should not produce static type errors', async () => { await expectTypeTestsToPassAsync(__filename); });
If for some reason your type definition test file(s) are not co-located to your Jest test file, you can pass absolute path(s) to them to
expectTypeTestsToPassAsync()instead of__filename.
Assertions
These assertions are re-exported from tsd.
expectType<T>(expression: T)
Asserts that the type of expression is identical to type T.
expectError<T = any>(expression: T)
Asserts that expression throws an error.
expectNotType<T>(expression: any)
Asserts that the type of expression is not identical to type T.
expectAssignable<T>(expression: T)
Asserts that the type of expression is assignable to type T.
expectNotAssignable<T>(expression: any)
Asserts that the type of expression is not assignable to type T.
expectDeprecated(expression: any)
Asserts that expression is marked as @deprecated.
expectNotDeprecated(expression: any)
Asserts that expression is not marked as @deprecated.