jest-ts-tocompile
v1.1.0
Published
Jest matchers to check if a TS file compiles
Downloads
9
Maintainers
Readme
jes-ts-tocompile
Custom Jest matcher for testing if a typescript file compiles.
Installation
- Install with npm
npm i jest-ts-tocompile
- Import and install
jest-ts-tocompile
in your jest setup file.
const toCompile = require('jest-ts-tocompile');
toCompile.install();
With TypeScript
When using typescript, you need to add the jest type augmentations to your project. In order to do this, create a jest.d.ts
file in your project root and add the following code:
declare namespace jest {
interface Matchers<R> {
toCompile(): R;
}
}
Usage
You can call expect
passing the file path of the typescript file to test and then call .toCompile()
to test if the file compiles.
import path from 'path';
describe('example files are correct', () => {
it('should compile', () => {
expect(path.join(__dirname, './example.ts')).toCompile();
});
})